Issue
Question: android:background is not giving effect in MaterialComponents.
In my project, I was using AppCompat
( <style name="DayTheme" parent="Theme.AppCompat.Light.NoActionBar">
)
and everything was working fine.
but, because of some requirement in my project, now, I've to use MaterialComponents
( <style name="DayTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
)
And because of that some UI looks bad.
Problem: In AppComapt, I was using android:background="@drawable/bg_circle_btn"
which was working fine, but in MaterialComponents, this background is not giving effect.
I tried to change color, shape n all but it's not giving effect.
<Button
android:id="@+id/custom_category_image"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/bg_circle_btn"
android:text="A"
android:textColor="@color/colorWhite"
android:textSize="12dp"
android:visibility="gone"
app:srcCompat="@drawable/ic_navigate_next_black_24dp" />
(I'm using button, because, instead of any fixed image, I'm setting the first letter of title in this button and this button is actually inside carview, so it'll be cirlce also.)
bg_circle_btn:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="?attr/toolbarcolor" />
<size
android:width="120dp"
android:height="120dp" />
</shape>
Please note that, in whole project, I need to use this background, so please do not give any other alternative ways.
Solution
You could use androidx.appcompat.widget.AppCompatButton
instead of Button
. This will solve your problem.
Besides this you can use android:backgroundTint
to change the color only.
To change both (Shape&Color) for com.google.android.material.button.MaterialButton
, you have to do this from you code:
setBackgroundResource(R.drawable.bg_circle_btn)
setBackgroundTintList(ColorStateList.valueOf(Color.RED))
Answered By - Md. Asaduzzaman
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.