進捗状況とボタンを含むビューを作成したかったのです。ビューのxmlを通して、ボタンとポールバーのスタイルを定義するフィールドを追加したかったのです。スタイル可能な作業
私がこれまで行ってきたが、それは動作しません:
<io.**.**.view.ButtonLoading android:id="@+id/b_recover_password"
android:layout_width="wrap_content"
android:gravity="center"
app:styleButton="@style/ButtonGrey"
app:styleProgress="@style/ProgressBar"
app:textButton="@string/recover_password"
android:layout_height="wrap_content"/>
はコード:
a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.ButtonLoading,
0, 0);
int buttonId = 0;// R.style.Widget_AppCompat_Button;
try {
buttonId = a.getResourceId(R.styleable.ButtonLoading_styleButton, 0);
} catch (Exception e) {
}
button = new Button(getContext(), attrs, buttonId);
LayoutParams lpButton = createLayoutParams();
button.setLayoutParams(lpButton);
color = button.getCurrentTextColor();
int progressId = 0;// R.style.Widget_AppCompat_ProgressBar;
try {
progressId = a.getResourceId(R.styleable.ButtonLoading_styleProgress, 0);
} catch (Exception e) {
}
progressBar = new ProgressBar(getContext(), attrs, progressId);
LayoutParams lpProgressBar = createLayoutParams();
lpProgressBar.addRule(RelativeLayout.CENTER_IN_PARENT);
progressBar.setLayoutParams(lpProgressBar);
LayoutParams lpRelativeLayout = createLayoutParams();
setLayoutParams(lpRelativeLayout);
addView(button);
addView(progressBar);
try {
String value = a.getString(R.styleable.ButtonLoading_textButton);
button.setText(value);
} catch (Exception e) {
}
a.recycle();
Styleable:
<declare-styleable name="ButtonLoading">
<attr name="styleButton" format="reference" />
<attr name="styleProgress" format="reference" />
<attr name="textButton" format="string" />
</declare-styleable>
誰かが私を助けて?おかげで
"それはうまくいかない"と言うと、それはどういう意味ですか? – Cheticamp
ボタンとプログレスバーのスタイルのセットが機能していません。デフォルトのスタイルに固執する。 –
このコードはカスタム表示です。その方法の中でどのような方法ですか。基本(拡大)ビューとは何ですか?プログレスバーとボタンのスタイルを投稿できますか? – Cheticamp