Skip to content

Instantly share code, notes, and snippets.

@bdiegel
bdiegel / android_recycler_vs_list.md
Last active November 11, 2015 14:50
Android Recycler vs ListView
@bdiegel
bdiegel / Android_Header_Underlined.md
Created November 5, 2015 01:19
Android Heading Underlined

Creating a Header

This creates a lable that is underlined. Looks nice when you need mark sections or groups of view elements.

  • use TextView

  • apply the list separator style

    <TextView android:id="@+id/profile_dates" style="?android:attr/listSeparatorTextViewStyle"

@bdiegel
bdiegel / Android_TouchDelegate.md
Last active November 26, 2015 01:51
Android TouchDelegate
@bdiegel
bdiegel / android_divider.md
Created November 2, 2015 17:11
Android_Custom_Divider

Create custom divider

Use styles to create custom divider

<style name="Divider">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">1dp</item>
    <item name="android:background">?android:attr/listDivider</item>
</style>

Using the style with View in a layout:

@bdiegel
bdiegel / android_maps_zoom.md
Created November 2, 2015 14:57
Android Maps Zoom Levels

Zoom levels

Maps have an integer “zoom level” which defines the resolution of the current view.

  • Level 0 (lowest zoom level): entire world can be seen on one map
  • Level 21+: individual buildings

Each succeeding zoom level doubles the precision in both horizontal and vertical dimensions:

256 * 2^N dp

Approximation in miles:

@bdiegel
bdiegel / android_maps_mylocation_button.md
Last active October 6, 2021 18:05
Android Maps v2 MyLocation Button Position

Change MyLocation button position

It's easy to enable Zoom and MyLocation buttons but annoying to change where they overlay the Map.

Options

  1. Use Map padding (are that will not overlap map controls)
  2. Disable them and implement your own (probably safer than hack below)
  3. Find the buttons by id and alter the layout params

Resources:

@bdiegel
bdiegel / android_searchview_style.md
Last active October 28, 2015 14:44
Android SearchView Styling

SearchView styles

Two good resources philio.me novoda

v21 example:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="searchViewStyle">@style/AppTheme.SearchView</item>
@bdiegel
bdiegel / android_transp_statusbar.md
Created October 28, 2015 14:37
Android Transparent Status Bar Fix

Fix status bar transparency

Note the adjusting the insets is a specific workaround for views that do not respect layout settings. View Pager has such problems.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setStatusBarTransparent() {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    getWindow().getDecorView().setSystemUiVisibility(
          View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

getWindow().setStatusBarColor(Color.TRANSPARENT);

@bdiegel
bdiegel / android_color_transparency.md
Last active October 28, 2015 14:30
Android Color Transparency

Set transparent color in android

Set color to #AARRGGBB where AA is the alpha channel.

  • #00000000 - full transparency
  • #80FFFFFF - 50% white
  • #CCFFFFFF - 80% white

Alpha channel values:

100% — FF