ResourcesCompat.getDrawable() vs AppCompatResources.getDrawable()

Here is my understanding after some testing: ContextCompat.getDrawable(@NonNull Context context, @DrawableRes int resId) ResourcesCompat.getDrawable(@NonNull Resources res, @DrawableRes int id, @Nullable Theme theme) AppCompatResources.getDrawable(@NonNull Context context, @DrawableRes int resId) VectorDrawableCompat.create(@NonNull Resources res, @DrawableRes int resId, @Nullable Theme theme The first thing I see is VectorDrawableCompat and ResourcesCompat can specify a theme. I) Without using AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); in … Read more

How to change the style of a DatePicker in android?

call like this button5.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub DialogFragment dialogfragment = new DatePickerDialogTheme(); dialogfragment.show(getFragmentManager(), “Theme”); } }); public static class DatePickerDialogTheme extends DialogFragment implements DatePickerDialog.OnDateSetListener{ @Override public Dialog onCreateDialog(Bundle savedInstanceState){ final Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = … Read more

Remove android.widget.Toolbar shadow

Use app:elevation=”0dp” instead of android:elevation on your toolbar. If it is not work, put your toolbar inside of a AppBarLayout and set app:elevation=”0dp”: <android.support.design.widget.AppBarLayout android:id=”@+id/appBarLayout” android:layout_width=”match_parent” android:layout_height=”wrap_content” app:elevation=”0dp”> … </android.support.design.widget.AppBarLayout>

MaterialComponents theme alert dialog buttons

I figured out what was causing this problem. I need to use different AlertDialog class: androidx.appcompat.app.AlertDialog When I switched to this everything started working as expected. Here’s where I found the solution: https://github.com/material-components/material-components-android/issues/162

Change the TextInputLayout outline color

Use this style to apply border color and border width like this : <style name=”LoginTextInputLayoutStyle” parent=”Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense”> <item name=”boxStrokeColor”>#fff</item> <item name=”boxStrokeWidth”>2dp</item> </style> get Additional details about styling from this link Add below line in your colors.xml file that overrides default color for TextInputLayout <color name=”mtrl_textinput_default_box_stroke_color” tools:override=”true”>#fff</color>

How can I style an Android Switch?

You can define the drawables that are used for the background, and the switcher part like this: <Switch android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:thumb=”@drawable/switch_thumb” android:track=”@drawable/switch_bg” /> Now you need to create a selector that defines the different states for the switcher drawable. Here the copies from the Android sources: <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_enabled=”false” android:drawable=”@drawable/switch_thumb_disabled_holo_light” /> <item android:state_pressed=”true” android:drawable=”@drawable/switch_thumb_pressed_holo_light” … Read more

Change status bar text color when primaryDark is white

I’m not sure what API level your trying to target, but if you can use API 23 specific stuff, you can add the following to your AppTheme styles.xml: <item name=”android:statusBarColor”>@color/colorPrimaryDark</item> <item name=”android:windowLightStatusBar”>true</item> when android:windowLightStatusBar is set to true, status bar text color will be able to be seen when the status bar color is white, … Read more