1
我有一個按鈕調用該函數的視圖添加到我的主要佈局:Android的addView設置TextView textColor爲白色?
private void createWrkHist() {
View addBtn = findViewById(R.id.addWrkHist);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) addBtn.getLayoutParams();
int aboveID = params.getRule(BELOW);
LayoutInflater inflator = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.work_history_table, null);
ViewGroup mainView = (ViewGroup) findViewById(R.id.mainForm);
RelativeLayout.LayoutParams insertParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
insertParams.addRule(BELOW, aboveID);
v.setLayoutParams(insertParams);
mainView.addView(v);
params.addRule(BELOW, R.id.wrkHist);
addBtn.setLayoutParams(params);
}
,因爲我使用了一些代碼,試圖專注於EditText
上添加視圖和它的工作被添加布局。但是,添加的視圖中的所有TextViews
都是完全白色的。我如何設置我添加到默認的視圖的樣式/主題?這是佈局我加入的XML:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/wrkHist"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:text="Position:"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small" />
<EditText
android:id="@+id/wrkPosition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_weight="15" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:text="Company:"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small" />
<EditText
android:id="@+id/wrkCompany"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_weight="15" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".5"
android:text="Start Date:"
android:textAlignment="textEnd"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small" />
<LinearLayout android:layout_weight="15">
<EditText
android:id="@+id/wrkStartDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_weight="7"
android:inputType="date" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:text="End Date:"
android:textAlignment="textEnd"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small" />
<EditText
android:id="@+id/wrkEndDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_weight="7"
android:inputType="date" />
</LinearLayout>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:text="Duties:"
android:textAlignment="textEnd"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small" />
<EditText
android:id="@+id/wrkDuties"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_weight="15"
android:lines="5" />
</TableRow>
</TableLayout>