TabLayout tab style

Define: <style name=”AppTabLayout” parent=”Widget.Design.TabLayout”> <item name=”tabMaxWidth”>@dimen/tab_max_width</item> <item name=”tabIndicatorColor”>?attr/colorAccent</item> <item name=”tabIndicatorHeight”>4dp</item> <item name=”tabPaddingStart”>6dp</item> <item name=”tabPaddingEnd”>6dp</item> <item name=”tabBackground”>?attr/selectableItemBackground</item> <item name=”tabTextAppearance”>@style/AppTabTextAppearance</item> <item name=”tabSelectedTextColor”>@color/range</item> </style> <!– for text –> <style name=”AppTabTextAppearance” parent=”TextAppearance.Design.Tab”> <item name=”android:textSize”>12sp</item> <item name=”android:textColor”>@color/orange</item> <item name=”textAllCaps”>false</item> </style> Apply: <android.support.design.widget.TabLayout style=”@style/AppTabLayout” app:tabTextAppearance=”@style/AppTabTextAppearance” android:layout_width=”match_parent” …. />

Android NavigationView menu group divider [duplicate]

Just give a unique id to each group. It will create a separator automatically. <?xml version=”1.0″ encoding=”utf-8″?> <menu xmlns:android=”http://schemas.android.com/apk/res/android”> <group android:id=”@+id/group_feature” android:checkableBehavior=”single”> <item android:id=”@+id/navdrawer_item_map” android:checked=”true” android:icon=”@drawable/ic_drawer_map” android:title=”@string/navdrawer_item_map”/> </group> <group android:id=”@+id/group_settings” android:checkableBehavior=”single”> <item android:id=”@+id/navdrawer_item_settings” android:icon=”@drawable/ic_drawer_settings” android:title=”@string/navdrawer_item_settings”/> </group> </menu>

How to set custom typeface to items in NavigationView?

just add following class file to your project. import android.graphics.Paint; import android.graphics.Typeface; import android.text.TextPaint; import android.text.style.TypefaceSpan; public class CustomTypefaceSpan extends TypefaceSpan { private final Typeface newType; public CustomTypefaceSpan(String family, Typeface type) { super(family); newType = type; } @Override public void updateDrawState(TextPaint ds) { applyCustomTypeFace(ds, newType); } @Override public void updateMeasureState(TextPaint paint) { applyCustomTypeFace(paint, newType); } … Read more

How to customize item background and item text color inside NavigationView?

itemBackground, itemIconTint and itemTextColor are simple xml-attributes that can be set, though you have to use a custom prefix instead of the android: one. Example <android.support.v4.widget.DrawerLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:id=”@+id/drawer_layout” android:layout_width=”match_parent” android:layout_height=”match_parent” android:fitsSystemWindows=”true”> <!– Other layout views –> <android.support.design.widget.NavigationView android:id=”@+id/nav_view” android:layout_width=”wrap_content” android:layout_height=”match_parent” android:layout_gravity=”start” android:fitsSystemWindows=”true” app:itemBackground=”@drawable/my_ripple” app:itemIconTint=”#2196f3″ app:itemTextColor=”#009688″ app:headerLayout=”@layout/nav_header” app:menu=”@menu/drawer_view” /> </android.support.v4.widget.DrawerLayout> Note: In this case the … Read more

TabLayout (Android Design Library) Text Color

Via XML attributes: <android.support.design.widget.TabLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” app:tabMode=”fixed” app:tabGravity=”fill” app:tabTextColor=”@color/your_unselected_text_color” app:tabSelectedTextColor=”@color/your_selected_text_color”/> Additionally, there are attributes like tabIndicatorColor or tabIndicatorHeight for further styling. In code: tabLayout.setTabTextColors( getResources().getColor(R.color.your_unselected_text_color), getResources().getColor(R.color.your_selected_text_color) ); Since this old way is deprecated as of API 23, the alternative is: tabLayout.setTabTextColors( ContextCompat.getColor(context, R.color.your_unselected_text_color), ContextCompat.getColor(context, R.color.your_selected_text_color) );

NavigationView and custom Layout

Here’s how I solved it, and worked perfectly: <android.support.design.widget.NavigationView android:id=”@+id/navigation” android:layout_width=”wrap_content” android:layout_height=”match_parent” android:layout_gravity=”start” android:fitsSystemWindows=”true”> <LinearLayout android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical”> <include layout=”@layout/nav_header” /> <ListView android:id=”@+id/lst_menu_items” android:layout_width=”match_parent” android:layout_height=”0dp” android:layout_weight=”1″ /> </LinearLayout> </android.support.design.widget.NavigationView>

TabLayout Tab Title text in Lower Case

If you add the following line to your TabLayout it should work: app:tabTextAppearance=”@android:style/TextAppearance.Widget.TabWidget” Use it like this: <android.support.design.widget.TabLayout android:id=”@+id/tabLayout” android:layout_width=”match_parent” android:layout_height=”wrap_content” app:tabIndicatorColor=”@android:color/white” app:tabIndicatorHeight=”2dp” app:tabTextAppearance=”@android:style/TextAppearance.Widget.TabWidget” app:tabSelectedTextColor=”@android:color/white” app:tabTextColor=”@android:color/white” />

TextInputLayout not showing EditText hint before user focus on it

Update: This is a bug that has been fixed in version 22.2.1 of the library. Original Answer: As mentioned by @shkschneider, this is a known bug. Github user @ljubisa987 recently posted a Gist for a workaround: https://gist.github.com/ljubisa987/e33cd5597da07172c55d As noted in the comments, the workaround only works on Android Lollipop and older. It does not work … Read more

How to set support library snackbar text color to something other than android:textColor?

I found this at What are the new features of Android Design Support Library and how to use its Snackbar? This worked for me for changing the text color in a Snackbar. Snackbar snack = Snackbar.make(view, R.string.message, Snackbar.LENGTH_LONG); View view = snack.getView(); TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text); tv.setTextColor(Color.WHITE); snack.show(); UPDATE: ANDROIDX: As dblackker points out … Read more

Android Multiline Snackbar

Just set the maxLines attribute of Snackbars Textview View snackbarView = snackbar.getView(); TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text); textView.setMaxLines(5); // show multiple line If you’re using the more recent “com.google.android.material:material:1.0.0″dependency, then you will use this: com.google.android.material.R.id.snackbar_text to access the Snackbar’s TextView. You can use even R.id.snackbar_text as well. it’s work for me.