在Android中设置样式上的TableRow样式、Android、TableRow

2023-09-06 14:52:54 作者:该2B的时候就千万别错过

使用Android SDK,似乎没有任何办法来设置样式上的表行。我想要做的是等效的:

Using the Android SDK, there doesn't seem to be any way to set the style on a table row. I want to do the equivalent of:

<TableRow
    style='@style/TableRow_classic' >

在code。我想是这样的:

in code. I would like something like:

TableRow row = new TableRow(this);
row.setStyle(R.style.TableRow_classic);

有谁知道怎么找呢?

Does anyone know how to find this?

推荐答案

我发现做到这一点,最好的解决办法是建立一个局部的布局重新presenting表列,定义的风格:

The best solution I've found to accomplish this is to create a "partial" layout representing the table row, with a style defined:

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    style="@style/tr_withborder" />

然后夸大它在你的code,动态使用:

Then inflate it in your code, to use dynamically:

TableRow tr = (TableRow) getLayoutInflater().inflate(R.layout.partial_table_row, null);

虽然不理想,但它确实为我工作。

While not ideal, it does work for me