我有一个卡片 View 。按钮默认颜色为灰色。我希望它看起来像右侧图像(如祝福)。这个右边的已经创建,将 backgroundtint 设置为白色,但在旧版本中它仍然显示灰色。
<android.support.v7.widget.CardView
android:id="@+id/programm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
android:layout_alignParentBottom="true"
android:layout_margin="6dp"
card_view:cardElevation="6dp"
android:layout_gravity="end|right"
card_view:cardBackgroundColor="@color/hotpink"
android:onClick="openNextActivity">
<Button
android:layout_width="wrap_content"
android:drawable="@color/white"
android:layout_height="wrap_content"
android:text="@string/Programme"
android:textColor="@color/hotpink"
android:onClick="openNextActivity"
/>
</android.support.v7.widget.CardView>
如果我将按钮的背景更改为白色,则整个颜色都会更改为白色:
<android.support.v7.widget.CardView
android:id="@+id/programm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
android:layout_alignParentBottom="true"
android:layout_margin="6dp"
card_view:cardElevation="6dp"
android:layout_gravity="end|right"
card_view:cardBackgroundColor="@color/hotpink"
android:onClick="openNextActivity">
<Button
android:layout_width="wrap_content"
android:drawable="@color/white"
android:background="@color/white"
android:layout_height="wrap_content"
android:text="@string/Programme"
android:textColor="@color/hotpink"
android:onClick="openNextActivity"
/>
</android.support.v7.widget.CardView>
根据谷歌搜索,这个默认的灰色是在一些主题中设置的。我可能需要覆盖一些主题并设置一些属性。但我不确定我需要更改什么。
最佳答案
试试这个:
<Button
android:layout_width="wrap_content"
android:text="Button Text"
android:theme="@style/myButtonTheme"
android:layout_height="wrap_content"/>
在您的 styles.xml
文件中设置此 myButtonTheme
:
<style name="myButtonTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColorPrimary">@color/white</item>
<item name="colorButtonNormal">#5552f1</item>
</style>
[在 colorButtonNormal
中设置你想要的背景颜色]
输出:
关于android - 将默认按钮颜色从灰色更改为白色android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41137830/