XMLは次のとおりです。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/LightStyle"
android:layout_width="fill_parent"
android:layout_height="55dip"
android:clickable="true"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" />
</RelativeLayout>
style
プログラムで属性を設定するにはどうすればよいですか?
技術的には、とにかくカスタムビューを使用して、プログラムでスタイルを適用できます。
private MyRelativeLayout extends RelativeLayout {
public MyRelativeLayout(Context context) {
super(context, null, R.style.LightStyle);
}
}
1つの引数のコンストラクターは、プログラムでビューをインスタンス化するときに使用されるコンストラクターです。
したがって、このコンストラクターを、スタイルパラメーターを受け取るスーパーにチェーンします。
RelativeLayout someLayout = new MyRelativeLayout(new ContextThemeWrapper(this,R.style.RadioButton));
または@Doriが簡単に指摘したように:
RelativeLayout someLayout = new RelativeLayout(new ContextThemeWrapper(activity,R.style.LightStyle));
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加