【发布时间】:2019-10-09 10:13:14
【问题描述】:
问题:android:background 在 MaterialComponents 中没有生效。
在我的项目中,我使用的是 AppCompat
(<style name="DayTheme" parent="Theme.AppCompat.Light.NoActionBar">)
一切正常。
但是,由于我的项目中有一些要求,现在我必须使用 MaterialComponents
(<style name="DayTheme" parent="Theme.MaterialComponents.Light.NoActionBar">)
因此,某些 UI 看起来很糟糕。
问题:在 AppComapt 中,我使用 android:background="@drawable/bg_circle_btn" 工作正常,但在 MaterialComponents 中,此背景不起作用。
我试图改变颜色,形状 n ,但它没有产生效果。
<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" />
(我使用的是按钮,因为我在此按钮中设置标题的第一个字母,而不是任何固定图像,并且此按钮实际上在 carview 内,所以它也是圆形的。)
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>
请注意,在整个项目中,我需要使用这个背景,所以请不要给出任何其他替代方式。
【问题讨论】:
-
你能发布一个有这个形状的屏幕吗?
-
@GabrieleMariotti 我无法捕捉到,因为正在发生一些变化。但是我会提供它,我告诉你,它不是圆形的,而且按钮也不是完全居中而是隐藏在左下角'
标签: android android-button material-components-android material-components