android - 将默认按钮颜色从灰色更改为白色android

标签 android button

我有一个卡片 View 。按钮默认颜色为灰色。我希望它看起来像右侧图像(如祝福)。这个右边的已经创建,将 backgroundtint 设置为白色,但在旧版本中它仍然显示灰色。 enter image description here

 <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>

enter image description here

根据谷歌搜索,这个默认的灰色是在一些主题中设置的。我可能需要覆盖一些主题并设置一些属性。但我不确定我需要更改什么。

最佳答案

试试这个:

<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 中设置你想要的背景颜色]

输出:

enter image description here

关于android - 将默认按钮颜色从灰色更改为白色android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41137830/

相关文章:

java - java类应该如何组织?

JavaFX 按钮递增和递减事件无法正常工作

Android:自定义形状的按钮

安卓图形用户界面 : trying to draw on a canvas

android - 如何将 ParseObject 的 createdAt 日期获取为字符串?

php - 使用下一个按钮替换页面上的内容,而不将我重定向到新页面

button - 具有接近度和可点击按钮的 IBeacons

html - IE上的paypal按钮问题

java - 应用程序只有在我手动进入时才能工作;否则异常

android - Firebase 事件不显示 NAME 属性