Android Background Drawable Not Working in Button Since Android Studio 4.1

The Android Studio 4.1 new-project wizard, for many of its templates, has the project use the Material Components for Android library. And, it sets up the default theme to be based on Theme.MaterialComponents.DayNight.DarkActionBar. A side effect of this is that any <Button> elements in a layout get turned into MaterialButton widgets, not regular Button widgets. … Read more

Change background popupMenu in Android

the following styles working perfectly for me. <style name=”popupMenuStyle” parent=”Theme.AppCompat.Light.DarkActionBar”> <item name=”android:textColor”>@color/color_white</item> <item name=”android:itemBackground”>@color/color_red</item> </style> here, parent should be the AppTheme parent and in your code use these lines. Context wrapper = new ContextThemeWrapper(context, R.style.popupMenuStyle); PopupMenu popup = new PopupMenu(wrapper, v); i hope it will work.

How to set Toolbar text and back arrow color

Chances are you are extending from the wrong parent. If not, you can try adding the style to the toolbar layout directly, if you want to override the theme’s settings. In your toolbar layout: <android.support.v7.widget.Toolbar xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize” android:minHeight=”?attr/actionBarSize” app:theme=”@style/ToolBarStyle” app:popupTheme=”@style/ToolBarPopupStyle” android:background=”@color/actionbar_color” /> In your styles: <!– ToolBar –> <style name=”ToolBarStyle” parent=”Theme.AppCompat”> <item … Read more

How to change the background color around a DialogFragment?

I had to set android:windowIsFloating to false and android:windowBackground to my custom color in the dialog style: styles.xml <resources xmlns:android=”http://schemas.android.com/apk/res/android”> <style name=”MyDialog” parent=”@android:style/Theme.Dialog”> <item name=”android:windowFrame”>@null</item> <item name=”android:windowBackground”>@color/orange_transparent</item> <item name=”android:windowIsFloating”>false</item> <item name=”android:windowContentOverlay”>@null</item> <item name=”android:windowTitleStyle”>@null</item> <item name=”android:colorBackgroundCacheHint”>@null</item> <item name=”android:windowAnimationStyle”>@android:style/Animation.Dialog</item> <item name=”android:windowSoftInputMode”>stateUnspecified|adjustPan</item> <item name=”android:gravity”>center</item> </style> </resources> MyDialogFragment public class MyDialogFragment extends DialogFragment { @Override public void onCreate(Bundle savedInstanceState) … Read more

Custom attributes in styles.xml

I figured it out! The answer is to NOT specify the namespace in the style. <?xml version=”1.0″ encoding=”utf-8″ ?> <resources xmlns:android=”http://schemas.android.com/apk/res/android”> <style name=”CustomStyle”> <item name=”android:layout_width”>wrap_content</item> <item name=”android:layout_height”>wrap_content</item> <item name=”custom_attr”>value</item> <!– tee hee –> </style> </resources>

How to make a smaller RatingBar?

How to glue the code given here … Step-1. You need your own rating stars in res/drawable … Step-2 In res/drawable you need ratingstars.xml as follow … <?xml version=”1.0″ encoding=”utf-8″?> <layer-list xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:id=”@android:id/background” android:drawable=”@drawable/star_empty” /> <item android:id=”@android:id/secondaryProgress” android:drawable=”@drawable/star_empty” /> <item android:id=”@android:id/progress” android:drawable=”@drawable/star” /> </layer-list> Step-3 In res/values you need styles.xml as follow … <?xml … Read more