有谁知道如何更改按钮颜色?
但是一个特定的按钮,而不是使用XML的应用程序的所有按钮。
android:backgroundTint属性甚至无法在Lollipop之前工作 使用AppCompat库。只有来自主题的colorButtonNormal才能使用 预棒棒糖。
这是真的吗?太可惜了
我使用这个drawable(是一个简单的绿色)和一个按钮,但是当我使用该按钮时,它比普通按钮更高。
这是 btn_green.xml
文件<?xml version="1.0" encoding="utf-8"?>
<item android:state_pressed="true"><shape>
<solid android:color="#ff5722" />
<corners android:radius="4dp" />
</shape></item>
<item android:state_focused="true"><shape android:shape="rectangle">
<solid android:color="#4caf50" />
<corners android:radius="4dip" />
<stroke android:width="1dip" android:color="#F0FC00" />
</shape></item>
<item><shape>
<solid android:color="#4caf50" />
<corners android:radius="4dp" />
</shape></item>
按钮是这样的:
<android.support.v7.widget.AppCompatButton
android:id="@+id/btnIngresar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/btn_green"
android:text="Hello"
android:textStyle="bold" />
当我使用drawable时,按钮高于普通按钮(没有drawable),我不知道为什么。
答案 0 :(得分:9)
如果你想要低于风格
将此样式添加到您的按钮
style="@style/Widget.AppCompat.Button.Borderless.Colored"
如果你想要这种风格
添加以下代码
style="@style/Widget.AppCompat.Button.Colored"
答案 1 :(得分:6)
有一种方法可以在棒棒糖前设备中设置BackgroundTint
。试试这个:
button.setSupportBackgroundTintList(getResources().getColorStateList(R.color.accentColor));
请参阅此答案:Lollipop's backgroundTint has no effect on a Button