Set state of BottomSheetDialogFragment to expanded

“Note that you cannot call the method before view layouts.” The above text is the clue. Dialogs have a listener that is fired once the dialog is shown. The dialog cannot be shown if it isn’t laid out. So, in the onCreateDialog() of your modal bottom sheet (BottomSheetFragment), just before returning the dialog (or anywhere, … Read more

Navigation drawer item icon not showing original colour

I found the answer here: https://stackoverflow.com/a/30632980/875249 To avoid the link its pretty straightforward: mNavigationView.setItemIconTintList(null); This disables all state based tinting, but you can also specify your own list too. It worked great for me! Here is where you can get the details on creating a color state list, but its pretty simple too: http://developer.android.com/reference/android/content/res/ColorStateList.html <selector … Read more

Difference between android-support-v7-appcompat and android-support-v4

UPDATE There are many changes done into support library since this question was answered. Good thing is, it is very well documented also. So you must read Support Library Documentation for more details and more available support library. Starting with Support Library release 26.0.0 (July 2017), the minimum supported API level across most support libraries … Read more

How to use and style new AlertDialog from appCompat 22.1 and above

When creating the AlertDialog you can set a theme to use. Example – Creating the Dialog AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.MyAlertDialogStyle); builder.setTitle(“AppCompatDialog”); builder.setMessage(“Lorem ipsum dolor…”); builder.setPositiveButton(“OK”, null); builder.setNegativeButton(“Cancel”, null); builder.show(); styles.xml – Custom style <style name=”MyAlertDialogStyle” parent=”Theme.AppCompat.Light.Dialog.Alert”> <!– Used for the buttons –> <item name=”colorAccent”>#FFC107</item> <!– Used for the title and text –> <item … Read more

How to create a simple divider in the new NavigationView?

All you need to do is define a group with an unique ID, I have checked the implementation if group has different id’s it will create a divider. Example menu, creating the separator: <menu 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” tools:context=”.MainActivity”> <group android:id=”@+id/grp1″ android:checkableBehavior=”single” > <item android:id=”@+id/navigation_item_1″ android:checked=”true” android:icon=”@drawable/ic_home” android:title=”@string/navigation_item_1″ /> </group> <group android:id=”@+id/grp2″ android:checkableBehavior=”single” > <item android:id=”@+id/navigation_item_2″ … Read more

Material Design not styling alert dialogs

UPDATED ON Aug 2019 WITH The Material components for android library: With the new Material components for Android library you can use the new com.google.android.material.dialog.MaterialAlertDialogBuilder class, which extends from the existing androidx.appcompat.AlertDialog.Builder class and provides support for the latest Material Design specifications. Just use something like this: new MaterialAlertDialogBuilder(context) .setTitle(“Dialog”) .setMessage(“Lorem ipsum dolor ….”) .setPositiveButton(“Ok”, … Read more

How to use support FileProvider for sharing content to other apps?

Using FileProvider from support library you have to manually grant and revoke permissions(at runtime) for other apps to read specific Uri. Use Context.grantUriPermission and Context.revokeUriPermission methods. For example: //grant permision for app with package “packegeName”, eg. before starting other app via intent context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); //revoke permisions context.revokeUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); As a … Read more

Change EditText hint color when using TextInputLayout

Define android:textColorHint in your application theme: <style name=”AppTheme” parent=”Theme.AppCompat.NoActionBar”> <item name=”colorPrimary”>@color/primary</item> <item name=”colorPrimaryDark”>@color/primary_dark</item> <item name=”colorAccent”>@color/accent</item> <item name=”android:textColorHint”>@color/secondary_text</item> </style> Source Or, in your layout, like: <android.support.design.widget.TextInputLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” android.support.design:hintTextAppearance=”@style/GreenTextInputLayout” android:textColorHint=”@color/secondary_text”>

NavigationView get/find header layout

Version 23.1.0 switches NavigationView to using a RecyclerView (rather than the previous ListView) and the header is added as one of those elements. This means it is not instantly available to call findViewById() – a layout pass is needed before it is attached to the NavigationView. For version 23.1.1 of the Support Library, you can … Read more