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