[MaterialButton] Can't set background color for it
See original GitHub issueDescription: Normally, we initialize a button background by android:background="@color/dark_orange"
, however, in my case, it can not change the color into orange, it always be white color.
Expected behavior: The button color should be orange, but it always be white. Also, i print it value of color like this: Log.e(TIMEORY_GLOBAL_TAG, "The color is:${goTravelBtn.background}")
, and the log result is:
2019-10-25 11:32:04.946 11308-11308/com.xxx.timeory E/Timeory GLOBAL_LOG: The color is:android.graphics.drawable.RippleDrawable@bdad964
Source code:
<com.google.android.material.button.MaterialButton
android:id="@+id/goTravel"
android:layout_width="280dp"
android:layout_height="54dp"
android:layout_marginBottom="36dp"
android:background="@color/dark_orange"
android:gravity="center"
android:textSize="@dimen/text_size_normal"
android:text="Go travelling"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Android API version: 29
Material Library version: 1.2.0-alpha-01
Device: Pixel 2 API 29
To help us triage faster, please check to make sure you are using the latest version of the library.
We also happily accept pull requests.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Can't change background color on MaterialButton without ...
1st Solution. You can use app:backgroundTint to change back ground color of MaterialButton <com.google.android.material.button.
Read more >MaterialButton - Android Developers
For unfilled buttons, this class uses ?attr/colorPrimary for the text color and transparent for the background tint. Add icons to the start, ...
Read more >How to Change the Background Color of Button in Android ...
Go to the layout folder and in the activity_main.xml file change the ConstraintLayout to LinearLayout and give its orientation vertical.
Read more >How to change background Color to MaterialButton from ...
I found the answer which is as below: I changed the following line materialButton.setBackgroundColor( ContextCompat.getColor(this@MyActivity, R.color.
Read more >Android Button Background Color Not changing - YouTube
Tech Bholi presents how to solve android studio button background color not changing problem easily. Created by: Bholi AnsariEdited by: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@MGaetan89 That’s right. I will use
AppCompatButton
instead, this widget is not effected by Materials 😃I had the same problem, and here is what it did: create a new style with a parent of a style of on of the material button styles and change the background color and background tint in it… hopefully it will work with you…