2

プログラムで UI コントロールを作成する必要がありますが、EditText が画面に表示されません。

これは一種のスケルトン xml で、プログラムでテーブル行を追加します。

<?xml version="1.0" encoding="utf-8"?>

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


    <LinearLayout android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical"
        android:paddingLeft="20dp"
        android:id="@+id/main_layout">

        <TableLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            android:id="@+id/myTable" >

        </TableLayout>


    </LinearLayout>

</ScrollView>

これは私のアクティビティの Java コードです。

TableLayout mainTable = (TableLayout) findViewById(R.id.myTable);
TableRow row = new TableRow(this);

TextView textView = new TextView(this);
textView.setText("Text1");
row.addView(textView);

EditText editText = new EditText(this, null, R.style.editTextStyle);
row.addView(editText);

mainTable.addView(row);

私のeditTextStyleは次のとおりです。

<style name="editTextStyle">
    <item name="android:paddingTop">10dp</item>
    <item name="android:paddingLeft">7dp</item>
    <item name="android:textSize">27sp</item>
    <item name="android:layout_width">150dp</item>
<item name="android:layout_height">50dp</item>
</style>

textView は正常に表示されていますが、editText はそうではありません。アイデアはありますか?

4

1 に答える 1

1

Android 4.0.3を使用している場合は、LinearLayoutで

android:focusable="true"
android:focusableInTouchMode="true"  

または、edittextの背景色を設定できます。

あなたのスタイルでアイテムを追加します

<item name="android:background">your required color </item>

次に、edittextを表示できます。

あなたはまたあなたの活動で次のようにすることができます

EditText editText = new EditText(this);
editText.setBackgroundColor(R.color.BLUE);
editText.setTextColor(R.color.BLACK);
row.addView(editText);

color.xmlで

<resources>
<color name="Black">#000000</color>
<color name="Blue">#FF006767</color>
</resources>
于 2012-08-01T10:52:09.080 に答える