2017-08-08 65 views
1

我已經創建了Android的Android對話框樣式&代碼被粘貼在below.But樣式似乎不適用於Android 6.0.1,三星手機。我有兩個共享屏幕截圖以及請幫助我。Android alert提示對話樣式不工作在三星6.0.1

代碼

<style name="GeneraButton1" parent="android:Widget.Button"> 
    <item name="android:textColor">@color/colorPrimary</item><item name="android:fontFamily">sans-serif</item><item name="android:textSize">@dimen/key_text</item><item name="android:gravity">center</item><item name="android:background">@drawable/general_button1_selector</item> 
</style> 

<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> 
    <!-- Used for the buttons --><item name="colorAccent">@color/white</item><!-- Used for the title and text --><item name="android:textColorPrimary">@color/colorPrimary</item><!-- Used for the title and text --><item name="android:textColor">@color/colorPrimary</item><!-- Used for the background --><item name="android:background">@color/white</item><item name="android:button">@style/GeneraButton</item><item name="android:actionButtonStyle">@style/GeneraButton</item> 
</style> 

JavaCode

public void showAlertDialog(String title, String message, IAlertDialogueInterface handler, final View view, boolean setPositiveButton, int posBtnString, int negBtnStr) { 
    final IAlertDialogueInterface internalHandler; 
    if (handler == null) { 
     internalHandler = new AlertHandler(); 
    } else { 
     internalHandler = handler; 
    } 
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, R.style.MyAlertDialogStyle); 
    alertDialogBuilder.setTitle(title); 
    alertDialogBuilder.setMessage(message); 
    alertDialogBuilder.setCancelable(false); 
    if (setPositiveButton) { 
     alertDialogBuilder.setPositiveButton(this.getString(posBtnString), 
      new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface arg0, int arg1) { 
        alertDialog.dismiss(); 
        internalHandler.onAlertButtonClick(arg1, view); 
       } 
      }); 
    } 
    alertDialogBuilder.setNegativeButton(this.getString(negBtnStr), new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      alertDialog.dismiss(); 
      internalHandler.onAlertButtonClick(which, view); 
     } 
    }); 

    alertDialog = alertDialogBuilder.create(); 

    if (view != null) { 
     alertDialog.setView(view); 
    } 
    alertDialog.show(); 
} 

MotoG4Plus(安卓7.0的屏幕截圖)enter image description here

三星(安卓6.0.1截屏)enter image description here

+0

你只有一個style.xml文件?我的意思是你沒有na v23/styles.xml? –

+1

請告訴您的警報對話框使用該風格,分享代碼。嘗試遵循本指南:https://stackoverflow.com/questions/2422562/how-to-change-theme-for-alertdialog – David

+0

@大衛編輯了代碼。請檢查。 –

回答

3

你必須這樣做,如果從代碼。如下所示:

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, R.style.YourAlertDialogStyle); 
    alertDialogBuilder.setTitle("title"); 
    alertDialogBuilder.setMessage("message"); 
    alertDialogBuilder.setCancelable(false); 
    final AlertDialog alertDialog = alertDialogBuilder.create(); 
    //2. now setup to change color of the button 
    alertDialog.setOnShowListener(
      new DialogInterface.OnShowListener() { 
      @Override 
      public void onShow(DialogInterface arg0) { 
       // like this set text color to all your buttons in dialog 
       alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(COLOR_YOU_WANT); 
      } 
    }); 

快樂編碼!

相關問題