更改按钮样式在整个应用程序 [英] Changing button style in the whole application

查看:151
本文介绍了更改按钮样式在整个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变我的按钮全部TEXTCOLOR在我的应用程序为白色,还试图使它大胆。但是,这并没有发生,我重写 Android的:Widget.Button 我正在开发的果冻豆4.1.2 我究竟做错了什么?

主题定义清单

 安卓主题=@风格/的Spui>
 

我喜欢那里的主题

 <样式名称=的Spui父=机器人:Theme.Holo.Light.DarkActionBar>
    <项目名称=机器人:按钮样式> @风格/ Buttonspui< /项目>
< /风格>
 

的样式按钮本身

 <样式名称=Buttonspui父=机器人:Widget.Button>
      <项目名称=机器人:背景> @可绘制/ btn_default_holo_light< /项目>
      <项目名称=安卓了minHeight> 48dip< /项目>
      <项目名称=安卓了minWidth> 64dip< /项目>
      <项目名称=机器人:文字颜色>#FFFFFF< /项目>
      <项目名称=机器人:TEXTSTYLE>大胆< /项目>
  < /风格>
 

按钮

 <按钮
     机器人:layout_width =match_parent
     机器人:layout_height =WRAP_CONTENT
     机器人:layout_marginTop =15dp
     机器人:文本=@字符串/编辑
     机器人:ID =@ + ID / btnEdit
     风格=@风格/ Buttonspui/>
 

解决方案

有关样式化的按钮,你可以使用这个:

转至绘制文件夹,使XML(如button.xml)文件调用风格,包含以下内容:

 < XML版本=1.0编码=UTF-8&GT?;

<选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

    <项目>
         <形状>
             <梯度安卓startColor =#449def机器人:endColor =#2f6699机器人:角=270/>
             <行程机器人:宽=1px的机器人:颜色=#000000/>
                <边角安卓bottomLeftRadius =0dp
                机器人:bottomRightRadius =0dp
                机器人:topLeftRadius =8DP
                机器人:topRightRadius =8DP/>
              <填充的android:左=10dp机器人:顶部=10dp机器人:右=10dp安卓底=10dp/>
         < /形状>
   < /项目>

< /选择器>
 

这是我的code可以使您需要的必要的修改

现在把它在你的布局XML(mainactivity.xml)像这样

 安卓背景=@可绘制/ button.xml
 

现在改变字体颜色和样式,你可以用它来作为价值文件夹中的styles.xml

部分如下

 <样式名称=按钮样式父=@安卓风格/ Widget.Button.Small>
    <项目名称=机器人:文字颜色>#FFFFFF< /项目>
    <项目名称=机器人:TEXTSIZE> 12SP< /项目>
    <项目名称=机器人:TEXTSTYLE>大胆< /项目>
< /风格>
 

现在把这个布局XML(mainactivity.xml)像这样

 风格=@风格/按钮样式
 

最后code是:

 <按钮
 机器人:layout_width =match_parent
 机器人:layout_height =WRAP_CONTENT
 机器人:layout_marginTop =15dp
 机器人:文本=@字符串/编辑
 机器人:ID =@ + ID / btnEdit
 机器人:背景=@可绘制/ button.xml
 风格=@风格/按钮样式
/>
 

希望这有助于:)

I'm trying to change all the TextColor of my buttons in my app to white and also trying to make it bold. But that isn't happening, I'm overwriting the android:Widget.Button I'm developing for Jelly Bean 4.1.2 What am I doing wrong?

Theme definition in manifest

android:theme="@style/spui" >

The theme where I like to

<style name="spui" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:buttonStyle">@style/Buttonspui</item>
</style>

The style for the button itself

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

The button

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

解决方案

For Styling your Button you can use this :

Go to the drawable folder and make a xml (e.g. button.xml) file called style which contains the following:

<?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>

This is my code you can make the necessary changes you want

Now call it in your layout xml (mainactivity.xml) like this

android:background="@drawable/button.xml"

Now to change the font color and style you can use the following which comes as part of the styles.xml in the values folder

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

Now call this in the layout xml (mainactivity.xml) like this

  style="@style/buttonStyle"

The final code is:

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

Hope this helps :)

这篇关于更改按钮样式在整个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆