0
を適用していない私は、次のように2つのボタンを持つユーザーのための簡単なダイアログを作成したい:Androidのカスタムダイアログボタンのスタイルは
ダイアログレイアウト(dialog_layout.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:orientation="vertical">
<Button
android:id="@+id/btn_select_choice_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="First Choice"
android:theme="@style/secondary_button_normal" />
<Button
android:id="@+id/btn_select_choice_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Second Choice"
android:theme="@style/secondary_button_normal" />
</LinearLayout>
secondary_button_normal:
<style name="secondary_button_normal" parent="Widget.AppCompat.Button">
<item name="colorButtonNormal">@color/button_secondary_normal_background</item>
<item name="android:textColor">@color/button_secondary_normal_text</item>
<item name="android:textSize">@dimen/button_textSize</item>
<item name="android:padding">@dimen/button_padding</item>
</style>
活動ののonCreate:
final Dialog selection = new Dialog(this);
selection.setContentView(R.layout.dialog_layout);
Button selectFirstChoice = (Button)selection.findViewById(R.id.btn_select_choice_1);
Button selectSecondChoice = (Button)selection.findViewById(R.id.btn_select_choice_2);
selectFirstChoice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do something
selection.dismiss();
}
});
selectSecondChoice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do something
selection.dismiss();
}
});
selection.setTitle("Some Title");
selection.setCancelable(false);
selection.show();
プレビューは大丈夫です:
ものの、それはヌガーでうまく動作しますが、私はロリポップ(5.0および5.1.1)上でそれを実行すると、ボタンがスタイリングなしです同じボタンのスタイリングは、ロリポップのアクティビティボタンに取り組ん:
私が何ができるか疑問に思いますDialogFragmentにダイアログを移動しようとしましたが、同じような動作に直面しました。
あなたのスタイルをres/values-v21/styles.xmlフォルダに配置しようとしましたか?また? – Mohamed
@モハメド私は無駄にしようとした。 – linkinu