2013-10-15 72 views
0

目前我有一個空檢查顯示和警報(這是正常工作),但我想這個警報出現與黑色免費而不是隻是警報對話框。顯示Android提醒黑色背景

我試過刪除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)); 
+0

你想顯示黑色背景的警報對話框嗎?showAlert功能是用來填充對話框嗎?如果是,請發佈您的showAlert代碼 – Manishika

回答

4

這裏是您展示如何改變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" 
    /> 

下面是一個簡單的例子,我已經快速解決了您的問題。希望這可以幫助。 乾杯