본문 바로가기

프로그램/ANDROID

안드로이드 TextView setBackgroundColor / 안드로이드 테이블 내용 글씨 색 주는 방법

반응형

안드로이드 TextView setBackgroundColor / 안드로이드 테이블 내용 글씨 색 주는 방법

 

화면에서 동적으로 생기는 table 작성 후

 

table안에 들어가는 내용에 글씨주는 방법 ~

 

주의 깊게 볼 부분은 색상 처리했습니다.

 

 

화면 game.xml

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

 

<Button
android:id="@+id/confButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="32dp"
android:text="@string/confirm_button"
tools:context=".GameActivity" />


<TableLayout
android:id="@+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#000000"
android:stretchColumns="*">
<View
android:layout_width="match_parent"
android:layout_height="2dp"
/>

</TableLayout>

</RelativeLayout>

---------------------------------------------------

android:background="#000000"

테이블의 배경색 설정입니다. 검정색으로 세팅했습니다. ㅋㅋ

 

<View
android:layout_width="match_parent"
android:layout_height="2dp"
/>

 

----> 테이블의 상단 구분선입니다.

 

---------------------------------------------------

 


public class GameActivity extends Activity implements OnClickListener

{

private static final int ff0033cc = 0; // 변수를 선언해서 사용했습니다.


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


setContentView(R.layout.game);
final TableLayout tableLayout = (TableLayout) findViewById(R.id.table);


for (int i = 0; i < 9; i++) {
// Creation row
final TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
// tableRow.

for(int j = 0 ; j < 9 ; j++){
final TextView text = new TextView(this);

text.setText( i + j + "|");
text.setBackgroundColor(ff0033cc); // 값은 int만 가능합니다.
text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));

tableRow.addView(text);
}

tableLayout.addView(tableRow);
}


}


public void onClick(View arg0) {

// TODO Auto-generated method stub

// String path = getFilesDir().getAbsolutePath();

Intent intent = null;

switch (arg0.getId()) {

}

 

}


}

 

------------------------------------

결과화면입니다.

 

 

 

반응형