簡體   English   中英

在黑色背景下顯示Android警報

[英]Showing Android Alert With Black Background

目前,我有一個顯示和警報為空的檢查(正常運行),但是我希望此警報以黑色顯示,而不僅僅是警報對話框。

我試着刪除finish(); 但這只是顯示警報,並在其后面放置以前的布局-並使警報保留在用戶的主屏幕上-我的問題是:如何將其修改為以簡單的黑色背景顯示警報?

StartActivity.java源代碼片段:

   } else {
                // ICS and UP
                if (isMDNPresent) {
                    //start SaveMDN activity
                    Intent i = new Intent(StartActivity.this, SaveMDN.class);
                    startActivity(i);
                    finish();
                } else {
                    //start Update Activity
                    Intent i = new Intent(StartActivity.this,
                            UpdateActivity.class);
                    startActivity(i);
                    finish();
                }
            }

SaveMDN.java源代碼片段:

 public class SaveMDN extends Activity {

EditText saveMDN;
TextView enterMdn;
Button save;
public static String mdn = "";
int version;
String temp;
TelephonyManager tm;
AlertDialog mErrorAlert = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (tm.getLine1Number()== null){
        showAlert(getString(R.string.insert_sim_dialog));

這是一個示例,向您展示如何更改alertDialog的背景。

public class MainActivity extends Activity implements OnClickListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button btn = (Button)findViewById(R.id.mybtn);
    btn.setOnClickListener(this);

}



public void showDialog(){

    AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom));
    builder.setMessage("Test")

           .setPositiveButton("YES", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   // FIRE ZE MISSILES!
               }
           })
           .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   // User cancelled the dialog
               }
           });

   builder.show();
    // Create the AlertDialog object and return it

}
@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.mybtn:
        showDialog();   
        break;

    default:
        break;
    }   
}

}

您需要將以下代碼添加到styles.xml中:

    <style name="AlertDialogCustom">
      <item name="android:textColor">#FF0000</item>
      <item name="android:background">#FF0000</item>
      <item name="android:typeface">normal</item>
      <item name="android:textSize">10sp</item>
     </style>

在您的用戶界面中:

    <Button 
    android:id="@+id/mybtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TEST BUTTON"
    />

這是一個簡單的示例,我已快速解決了您的問題。 希望這可以幫助。 干杯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM