大佬教程收集整理的这篇文章主要介绍了android – 在整个应用程序中更改按钮样式,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
清单中的主题定义
android:theme="@style/spui" >
我喜欢的主题
<style name="spui" parent="android:Theme.Holo.Light.DarkActionBar"> <item name="android:buttonStyle">@style/Buttonspui</item> </style>
按钮本身的样式
<style name="Buttonspui" parent="android:Widget.button"> <item name="android:BACkground">@drawable/btn_default_holo_light</item> <item name="android:minHeight">48dip</item> <item name="android:minWidth">64dip</item> <item name="android:textColor">#ffffff</item> <item name="android:textStyle">bold</item> </style>
按钮
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:text="@String/edit" android:id="@+id/btnEdit" style="@style/Buttonspui"/>
转到drawable文件夹并创建一个名为“style”的XML(例如button.xml)文件,其中包含以下内容:
<?xml version="1.0" encoding="utf-8"?> <SELEctor xmlns:android="http://scheR_486_11845@as.android.com/apk/res/android"> <item> <shape> <gradient android:startColor="#449def" android:endColor="#2f6699" android:angle="270" /> <stroke android:width="1px" android:color="#000000" /> <corners android:bottomLefTradius="0dp" android:bottomRighTradius="0dp" android:topLefTradius="8dp" android:topRighTradius="8dp"/> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> </SELEctor>
这是我的代码,您可以进行所需的必要更改
现在在你的布局XML(mainactivity.xml)中调用它
android:BACkground="@drawable/button.xml"
现在要更改字体颜色和样式,您可以使用以下值作为values文件夹中的styles.xml的一部分
<style name="buttonStyle" parent="@android:style/Widget.button.small"> <item name="android:textColor">#FFFFFF</item> <item name="android:textSize">12sp</item> <item name="android:textStyle">bold</item> </style>
现在在布局XML(mainactivity.xml)中调用它,就像这样
style="@style/buttonStyle"
最终的代码是:
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:text="@String/edit" android:id="@+id/btnEdit" android:BACkground="@drawable/button.xml" style="@style/buttonStyle" />
希望这可以帮助 :)
以上是大佬教程为你收集整理的android – 在整个应用程序中更改按钮样式全部内容,希望文章能够帮你解决android – 在整个应用程序中更改按钮样式所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。