【问题标题】:How to set the textsize, textcolor and other parameters for the imagebutton in android?android中如何设置imagebutton的textsize、textcolor等参数?
【发布时间】:2012-08-08 10:00:44
【问题描述】:

如何在一个xml中设置文本大小、文本颜色和其他参数,然后将它们分配给android中的imagebutton? 我可以为每个按钮手动设置参数,但如果按钮超过 3 个,那就是一场噩梦。这样做的最佳做法是什么?

【问题讨论】:

  • 了解一些可重用资源的 Android 开发基础知识,您可以在 /res/values/ 中创建样式并在外观相似的小部件中使用这些样式,通过 style="@style/your_style"

标签: android xml user-interface imagebutton


【解决方案1】:

【讨论】:

    【解决方案2】:

    根据您的要求创建一个style,将其添加到您的按钮中,例如style="@style/your_style"。看这个教程Styles and Themes

    【讨论】:

      【解决方案3】:
      <?xml version="1.0" encoding="utf-8"?>
      <resources>
          <style name="CustomText" parent="@style/Text">
              <item name="android:textSize">20sp</item>
              <item name="android:textColor">#008</item>
          </style>
      </resources>
      
      <?xml version="1.0" encoding="utf-8"?>
      <EditText
          style="@style/CustomText"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Hello, World!" />
      
      
      <TextView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:textColor="#00FF00"
          android:typeface="monospace"
          android:text="@string/hello" />
      

      【讨论】:

      • 警告:在布局文件中发现意外的文本:“20sp”。我不知道这是否重要,但我将样式 xml 放在可绘制文件夹中
      猜你喜欢
      • 1970-01-01
      • 2022-12-24
      • 1970-01-01
      • 1970-01-01
      • 2015-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多