前提・実現したいこと
androidstudio/javaでのTextViewなどの背景色変更の簡略化
該当のソースコード
tablelayoutとtextviewで作成した表のtextview部分を条件により背景色変更を行っています。
特にエラーが発生しているわけではないのですが、一つ一つのtextviewの背景を順に塗っていく作業と背景色の一括クリアでソースコードが不格好に増大していっている状態です。
不明点としては、現状id毎にすべて色を指定して並べている作業をなんとかグループ化など一括操作できるようであれば行いたいです。
また、できればtablelayoutのタグで囲んだ領域のみをページロード時のように初期化する機能等はありますでしょうか。
java
1Actibityファイル 2setBackgroundColor(findViewById(R.id.test), Color.rgb(127, 255, 212)); 3setBackgroundColor(findViewById(R.id.test2), Color.rgb(127, 255, 212)); 4 5private void setBackgroundColor(View target, int color){ 6 target.setBackgroundColor(color); 7} 8 9xmlファイル 10<TableLayout 11 android:layout_width="215dp" 12 android:layout_height="142dp" 13 android:layout_marginTop="188dp" 14 app:layout_constraintHorizontal_bias="0.905" 15 app:layout_constraintLeft_toLeftOf="parent" 16 app:layout_constraintRight_toRightOf="parent" 17 app:layout_constraintTop_toTopOf="parent"> 18 19 <TableRow 20 android:layout_width="match_parent" 21 android:layout_height="match_parent" 22 android:background="#003366" 23 android:text="test"> 24 25 <TextView 26 android:id="@+id/test" 27 android:layout_width="fill_parent" 28 android:layout_height="fill_parent" 29 android:layout_weight="1" 30 android:background="#003366" 31 android:gravity="center" 32 android:text="1" 33 android:textColor="#FFFFFF" 34 android:textStyle="bold"></TextView> 35 36 <TextView 37 android:id="@+id/test2" 38 android:layout_width="fill_parent" 39 android:layout_height="fill_parent" 40 android:layout_marginLeft="1dip" 41 android:layout_weight="1" 42 android:background="#003366" 43 android:gravity="center" 44 android:text="2" 45 android:textColor="#FFFFFF" 46 android:textStyle="bold"></TextView> 47 </TableRow> 48~~~~~~~省略~~~~~~~~ 49
補足情報(FW/ツールのバージョンなど)
androidstudio3.2.1
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。