有谁知道如何更改按钮颜色?
只是一个特定的按钮,而不是使用 XML 的应用程序的所有按钮。
The android:backgroundTint attribute doesn't work on pre-Lollipop even with AppCompat library. Only colorButtonNormal from theme works on pre-Lollipop.
这是真的吗?真可惜
我正在使用这个带有按钮的可绘制对象(是一种简单的绿色),但是当我使用该按钮时,结果发现该按钮比普通按钮高。
这是文件 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),我不知道为什么。
最佳答案
如果你想要下面的样式
将此样式添加到您的按钮
style="@style/Widget.AppCompat.Button.Borderless.Colored"
如果你想要这种风格
添加下面的代码
style="@style/Widget.AppCompat.Button.Colored"
关于java - 使用 AppCompat 在 Android 中为按钮着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30668432/