android – 在整个应用程序中更改按钮样式

android – 在整个应用程序中更改按钮样式,第1张

概述我正在尝试将我的应用程序中所有按钮的TextColor更改为白色,并尝试将其设置为粗体.但这没有发生,我正在覆盖 android:Widget.Button 我正在为Jelly Bean 4.1.2开发 我究竟做错了什么? 清单中的主题定义 android:theme="@style/spui" > 我喜欢的主题 <style name="spui" parent="android:Theme.H 我正在尝试将我的应用程序中所有按钮的Textcolor更改为白色,并尝试将其设置为粗体.但这没有发生,我正在覆盖 android:Widget.button
我正在为Jelly Bean 4.1.2开发
我究竟做错了什么?

清单中的主题定义

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"     />
解决方法 要设置button的样式,您可以使用:

转到drawable文件夹并创建一个名为“style”的XML(例如button.xml)文件,其中包含以下内容:

<?xml version="1.0" enCoding="utf-8"?> <selector xmlns:androID="http://schemas.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"

现在要@R_965_6502@颜色和样式,您可以使用以下值作为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)中调用它,就像这样

  

最终的代码是:

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

希望这可以帮助 :)

总结

以上是内存溢出为你收集整理的android – 在整个应用程序中更改按钮样式全部内容,希望文章能够帮你解决android – 在整个应用程序中更改按钮样式所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1134903.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存