android - Android TableLayout 中每一行的样式相同

标签 android android-layout

在 Android XML 中有什么方法可以同时为 TableLayout 中的所有行设置相同的样式(或样式参数,如填充)?

我想避免做的是:

<TableLayout>
    <TableRow style="@style/MyStyle">...</TableRow>
    <TableRow style="@style/MyStyle">...</TableRow>
    <TableRow style="@style/MyStyle">...</TableRow>
    <TableRow style="@style/MyStyle">...</TableRow>
    ...
</TableLayout>

最佳答案

您可以通过在 res/values 目录中创建 XML 文件来定义自己的样式。所以,假设您想要红色和粗体文本,然后您创建一个包含以下内容的文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="MyRedTheme" parent="android:Theme.Light">
    <item name="android:textAppearance">@style/MyRedTextAppearance</item>
  </style>
  <style name="MyRedTextAppearance" parent="@android:style/TextAppearance">
    <item name="android:textColor">#F00</item>
    <item name="android:textStyle">bold</item>
  </style>
</resources>

您可以随意命名,例如res/values/red.xml。然后,您唯一需要做的就是在您想要的小部件中使用该 View ,例如:

  <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView
        style="@style/MyRedTheme"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="This is red, isn't it?"
        />
    </LinearLayout>

更多引用click here

关于android - Android TableLayout 中每一行的样式相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30642623/

相关文章:

android - 如何在 Android 中查找我的 Google map 版本

android - 为什么我将 Razorpay 与 Flutter 结合使用会出现此错误 => Uncaught TypeError :window. getDeviceDetails is not a function and BAD_REQUEST_ERROR?

android - 在哪里设置 View 的大小,它是扩展 RelativeLayout 的类的字段?

android - 标签 : TextLayoutCache Text: Cache Value deleted

android - 按钮在设备中不可见

android - 检查 BrowseFragment Android TV 中的标题项焦点

android - OCR,将识别的文本放在相机 View 上

android - RecyclerView 奇怪的行为膨胀细胞

android - Android 上的 XMPP Smack 4.1.0 rc1 ACCES(权限被拒绝)

android - 检查这是否是 LinearLayout 中的最后一个 EditText?