【发布时间】:2022-08-15 14:17:42
【问题描述】:
我在 Android Studio 中有一个表格,当我单击一个单元格时,它应该变成绿色或任何其他颜色,这并不重要,但我不知道如何实现它。 我现在只有 xml 文件,我不确定要添加的确切内容和位置。 这是我第一次尝试实现类似的东西,我不知道我应该从哪里开始,或者我需要什么。
这是xml:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<TableLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_width=\"fill_parent\"
android:layout_height=\"match_parent\"
android:gravity=\"center\"
android:stretchColumns=\"0,1,2\">
<TableRow
android:id=\"@+id/blank\"
android:layout_width=\"fill_parent\"
android:layout_height=\"wrap_content\"
android:layout_margin=\"1dp\"
android:background=\"#FFFFFF\">
<TableRow
android:layout_width=\"fill_parent\"
android:layout_height=\"0dp\"
android:layout_margin=\"1dp\"
android:layout_weight=\"1\"
android:background=\"#000000\">
</TableRow>
</TableRow>
<TableRow
android:layout_width=\"fill_parent\"
android:layout_height=\"0dp\"
android:layout_margin=\"1dp\"
android:layout_weight=\"1\"
android:background=\"#000000\"
>
<TextView
android:layout_width=\"match_parent\"
android:layout_height=\"match_parent\"
android:layout_column=\"0\"
android:layout_margin=\"1dp\"
android:background=\"#FFFFFF\"
android:gravity=\"center\"
android:text=\"Text\"
android:textAppearance=\"?android:attr/textAppearanceLarge\"
android:textStyle=\"bold\" />
<TextView
android:layout_width=\"wrap_content\"
android:layout_height=\"match_parent\"
android:layout_column=\"1\"
android:layout_margin=\"1dp\"
android:background=\"#FFFFFF\"
android:gravity=\"center\"
android:text=\"Text\"
android:textAppearance=\"?android:attr/textAppearanceLarge\"
android:textStyle=\"bold\" />
<TextView
android:layout_width=\"wrap_content\"
android:layout_height=\"match_parent\"
android:layout_column=\"2\"
android:layout_margin=\"1dp\"
android:background=\"#FFFFFF\"
android:gravity=\"center\"
android:text=\"Text\"
android:textAppearance=\"?android:attr/textAppearanceLarge\"
android:textStyle=\"bold\" />
</TableRow>
<TableRow
android:layout_width=\"fill_parent\"
android:layout_height=\"0dp\"
android:layout_margin=\"1dp\"
android:layout_weight=\"1\"
android:background=\"#000000\">
<TextView
android:layout_width=\"match_parent\"
android:layout_height=\"match_parent\"
android:layout_column=\"0\"
android:layout_margin=\"1dp\"
android:background=\"#FFFFFF\"
android:gravity=\"center\"
android:text=\" Text\"
android:textAppearance=\"?android:attr/textAppearanceLarge\" />
<TextView
android:layout_width=\"wrap_content\"
android:layout_height=\"match_parent\"
android:layout_column=\"1\"
android:layout_margin=\"1dp\"
android:background=\"#FFFFFF\"
android:gravity=\"center\"
android:text=\" Text\"
android:textAppearance=\"?android:attr/textAppearanceLarge\" />
<TextView
android:layout_width=\"wrap_content\"
android:layout_height=\"match_parent\"
android:layout_column=\"2\"
android:layout_margin=\"1dp\"
android:background=\"#FFFFFF\"
android:gravity=\"center\"
android:text=\" Text\"
android:textAppearance=\"?android:attr/textAppearanceLarge\" />
</TableRow>
<TableRow
android:layout_width=\"fill_parent\"
android:layout_height=\"0dp\"
android:layout_margin=\"1dp\"
android:layout_weight=\"1\"
android:background=\"#000000\">
<TextView
android:layout_width=\"match_parent\"
android:layout_height=\"match_parent\"
android:layout_column=\"0\"
android:layout_margin=\"1dp\"
android:background=\"#FFFFFF\"
android:gravity=\"center\"
android:text=\" Text\"
android:textAppearance=\"?android:attr/textAppearanceLarge\" />
<TextView
android:layout_width=\"wrap_content\"
android:layout_height=\"match_parent\"
android:layout_column=\"1\"
android:layout_margin=\"1dp\"
android:background=\"#FFFFFF\"
android:gravity=\"center\"
android:text=\" Text\"
android:textAppearance=\"?android:attr/textAppearanceLarge\" />
<TextView
android:layout_width=\"wrap_content\"
android:layout_height=\"match_parent\"
android:layout_column=\"2\"
android:layout_margin=\"1dp\"
android:background=\"#FFFFFF\"
android:gravity=\"center\"
android:text=\" Text\"
android:textAppearance=\"?android:attr/textAppearanceLarge\" />
</TableRow>
</TableLayout>
有人可以帮忙吗? 非常感谢。
-
我们希望您诚实地尝试解决方案,发布该尝试,然后询问有关它的具体问题(即解释它为什么不起作用或它有什么问题)。
标签: java android android-studio onclick