【问题标题】:How to change to text color of all the button in my app?如何更改我的应用程序中所有按钮的文本颜色?
【发布时间】:2019-03-20 21:26:05
【问题描述】:

如何更改应用程序中所有按钮的文本颜色?现在唯一认为要做的工作是:

  <style name="MyTheme" parent="@android:style/Theme.Material.Light.NoActionBar"> 

    <item name="android:textColor">#ff0000</item>

  </style>

但我有点担心使用android:textColor who seam 不仅会影响按钮

我试过了,但是没用:

  <style name="BBButtonColor" parent="@android:style/Widget.Button">
    <item name="android:textColor">#ff0000</item>
  </style> 

  <style name="BBButtonStyle" parent="@android:style/Widget.Button">
    <item name="android:textColor">#ff0000</item>
  </style> 

  <style name="BBBorderlessButtonStyle" parent="@android:style/Widget.Button">
    <item name="android:textColor">#ff0000</item>
  </style> 


  <style name="MyTheme" parent="@android:style/Theme.Material.Light.NoActionBar"> 

    <item name="android:textAppearanceButton">@style/BBButtonColor</item> 
    <item name="android:buttonStyle">@style/BBButtonStyle</item>
    <item name="android:borderlessButtonStyle">@style/BBBorderlessButtonStyle</item>
    <item name="android:colorButtonNormal">#ff0000</item>

  </style>

这主要是我想要更改的弹出对话框中按钮的颜色

【问题讨论】:

  • 我认为这个之前的答案非常适合您的需求:stackoverflow.com/questions/36261421/…
  • @RaviRupareliya:我已经阅读了这个问题,但其中没有任何内容对我有用:(
  • @RiccardoCoppola 我也已经阅读了这个问题,但其中没有任何内容对我有用:(
  • @lok​​i 您能否通过添加一些文件来详细说明问题,例如styles.xmlAndroidManifest.xmllayout.xml 之一等。这将有助于我们缩小问题范围。

标签: android android-button android-theme android-styles


【解决方案1】:

Loki,你可以试试这个。这应该会改变您应用中所有按钮的颜色。

<style name="BBButtonColor" parent="android:Widget.Button">
    <item name="android:textColor">#FF0000</item>
</style>

您尝试使用@android:style/Widget.Button,而不是使用android:Widget.Button 并检查。让我知道这是否有效。

【讨论】:

    【解决方案2】:

    你可以试试这个:

    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:buttonStyle">@style/ButtonColor</item>
        <item name="colorButtonNormal">@color/colorname</item>
    </style>
    
    <style name="ButtonColor" parent="@android:style/Widget.Button">
        <item name="android:textColor">@color/colorname</item>
    </style>
    

    和/更改清单文件中的这一行:

    android:theme="@style/AppTheme.Base
    

    【讨论】:

      【解决方案3】:

      您应该为按钮创建新样式,类似这样:

      <style name="optionsButton">
              <item name="android:layout_width">70dp</item>
              <item name="android:layout_height">wrap_content</item>
              <item name="android:background">@color/white</item>
              <item name="android:textColor">@color/black</item>
              <item name="android:textSize">15sp</item>
          </style>
      

      现在您可以在布局 xml 中为您想要的每个按钮设置此样式,例如:

                      <Button
                      android:id="@+id/payCashBtn"
                      style="@style/optionsButton"
                      android:text="Cash" />
      

      您可以看到我在样式中设置了 layout_width 和 height,因此我所有使用此样式的按钮都将具有相同的参数,但是您可以为每个按钮设置不同的值,或者如果您多次使用它,则可以创建多个样式。希望对你有帮助。

      【讨论】:

      • 不,我需要在全球范围内进行。我的应用中没有使用任何布局,一切都来自材料设计
      猜你喜欢
      • 2013-11-12
      • 2012-10-19
      • 2021-11-12
      • 1970-01-01
      • 2012-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-05
      相关资源
      最近更新 更多