android button style
时间: 2023-07-19 17:34:24 浏览: 205
可以通过在XML文件中定义Button的style来自定义Button的样式。以下是一个简单的例子:
首先,在res/values/styles.xml文件中定义一个新的style,例如:
```xml
<style name="MyButtonStyle" parent="@android:style/Widget.Button">
<item name="android:textColor">#ffffff</item>
<item name="android:background">#0099cc</item>
<item name="android:padding">10dp</item>
</style>
```
其中,parent属性指定了Button的父样式,这里使用了Android内置的Widget.Button样式。接着,定义了三个属性:
- android:textColor:按钮文本颜色。
- android:background:按钮背景颜色。
- android:padding:按钮内边距。
接着,在布局文件中使用这个样式,例如:
```xml
<Button
android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Button"
style="@style/MyButtonStyle" />
```
其中,style属性指定了使用的样式为MyButtonStyle。
这样,就可以自定义Button的样式了。需要注意的是,Button的样式可以通过定义不同的属性进行修改,这里只是一个简单的例子。
阅读全文
相关推荐


















