BottomNavigationView is not full width on Android

The BottomNavigationView is not displayed as full width because it is not supposed to.
If you want to fill the space behind the BottomNavigationView, you can set the background color of the view to be the same color as the items background:

<android.support.design.widget.BottomNavigationView
     android:background="@color/bottom_view_color"
     app:itemBackground="@color/bottom_view_color"

     // .... />

References
http://stackoverflow.com/questions/41432902/bottomnavigationview-is-not-full-width/

Determine when Fragment becomes visible in ViewPager

@Override
public void setUserVisibleHint(boolean visible)
{
    super.setUserVisibleHint(visible);
    if (visible && isResumed())
    {
        //Only manually call onResume if fragment is already visible
        //Otherwise allow natural fragment lifecycle to call onResume
        onResume();
    }
}

@Override
public void onResume()
{
    super.onResume();
    if (!getUserVisibleHint())
    {
        return;
    }

    //INSERT CUSTOM CODE HERE
}

References
http://stackoverflow.com/questions/10024739/how-to-determine-when-fragment-becomes-visible-in-viewpager
https://developer.android.com/reference/android/app/Fragment.html#setUserVisibleHint(boolean)
https://developer.android.com/reference/android/app/Fragment.html#setMenuVisibility(boolean)

Android Get Screen width and height

DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;

In a view you need to do something like this:

((Activity) getContext()).getWindowManager()
                         .getDefaultDisplay()
                         .getMetrics(displayMetrics);

Or

public static int getScreenWidth() {
    return Resources.getSystem().getDisplayMetrics().widthPixels;
}

public static int getScreenHeight() {
    return Resources.getSystem().getDisplayMetrics().heightPixels;
}

References
http://stackoverflow.com/questions/4743116/get-screen-width-and-height

Android Percent Layouts

build.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:percent:25.3.1'
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="ir.mhdr.a081.MainActivity">

    <View android:background="@color/colorPrimary"
        app:layout_heightPercent="50%"
        app:layout_marginLeftPercent="25%"
        app:layout_marginTopPercent="25%"
        app:layout_widthPercent="50%"
        android:id="@+id/viewColor">

    </View>

    <android.support.percent.PercentFrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/viewColor"
        android:layout_centerInParent="true"
        android:layout_alignParentBottom="true">

        <View
            android:layout_gravity="center"
            android:background="@color/colorAccent"
            app:layout_heightPercent="30%"
            app:layout_widthPercent="50%" />
    </android.support.percent.PercentFrameLayout>

</android.support.percent.PercentRelativeLayout>

References
https://github.com/mhdr/AndroidSamples/tree/master/081
https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html
https://developer.android.com/reference/android/support/percent/PercentFrameLayout.html
https://developer.android.com/topic/libraries/support-library/packages.html

Android Gauge Library

root build.gradle

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

build.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.github.Paroca72:sc-widgets:2.1.2'
    testCompile 'junit:junit:4.12'

}

References
https://github.com/mhdr/AndroidSamples/tree/master/080

Android Gradient Background Color for Button

/res/drawable/gradient_color.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >

    <gradient
        android:angle="135"
        android:startColor="@color/colorBackground"
        android:endColor="@color/colorPrimary"
        android:type="linear" />

    <corners
        android:radius="0dp"/>

</shape>

activity_main.xml

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/editTextWeight"
                android:background="@drawable/gradient_color">
                <Button
                    android:id="@+id/buttonStart"
                    android:background="?android:attr/selectableItemBackground"
                    android:textAllCaps="true"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/start"
                    />
            </FrameLayout>

References
https://github.com/mhdr/AndroidSamples/tree/master/077

Android Focus on TextView

activity_main.xml

            <TextView
                android:id="@+id/textViewProfileName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_below="@+id/textViewFirstRunHeader2"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="center|start"
                android:text="@string/profile_name"
                android:textColor="@android:color/black"
                android:textSize="16sp"
                android:textStyle="bold" />

MainActivity.java

        textViewProfileName= (TextView) findViewById(R.id.textViewProfileName);
        textViewProfileName.requestFocusFromTouch();

References
https://github.com/mhdr/AndroidSamples/tree/master/075