2013-05-27 21 views
5

Tôi đang cố gắng tạo ba mục của màu xanh lá cây AlertDialog này. Vấn đề là hiện tại một nền màu xanh lá cây xuất hiện phía sau cảnh báo, và hai trong số các mục không xuất hiện màu xanh lá cây. Tôi hiện thiết lập các phong cách của AlertDialog với mã này:AlertDialog.Bầu nền của mục công trình xây dựng

final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.ListRow)); 

Trong styles.xml tôi, tôi có phong cách này:

<style name="ListRow"> 
    <item name="android:background">@color/forest_green</item> 
    <item name="android:textSize">18sp</item> 
    <item name="android:textColor">@color/dialog_text</item> 
</style> 

enter image description here

+0

vấn đề của bạn với mã này là gì không? –

+0

Không sử dụng 'android: background' trên * chủ đề *. Mọi thứ không xác định nền của nó sẽ có màu xanh lá cây. Thay vào đó, bạn ghi đè 'android: buttonBarStyle' và 'android: buttonBarButtonStyle' thay thế như thế nào? –

+0

Bạn có thể xem các hướng dẫn sau: http://blog.supenta.com/2014/07/02/how-to-style-alertdialogs-like-a-pro/ và http://www.materialdoc.com/alert/ – noongiya95

Trả lời

-1

Sử dụng styles.xml như

này
<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<style name="AlertDialogCustom" parent="@android:style/AlertDialog"> 
    <item name="android:textColor">#00FF00</item> 
    <item name="android:typeface">monospace</item> 
    <item name="android:textSize">10sp</item> 
</style> 

+3

bạn đã thử trước khi đăng? điều này thậm chí không biên dịch ... – moonlightcheese

+0

Tôi đã sử dụng lỗi này: lỗi: Lỗi khi truy xuất phụ huynh cho mục: Không tìm thấy tài nguyên nào khớp với tên đã cho '@android: style/AlertDialog'. –

0

bạn có thể thiết lập tùy chỉnh xem lập trình như cách này ..

LayoutInflater inflater = getLayoutInflater(); 
View dialoglayout = inflater.inflate(R.layout.dialog_layout, (ViewGroup) getCurrentFocus()); 
AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setView(dialoglayout); 
builder.show(); 

tạo dialog_layout.xml trong bố trí của bạn với nền màu xanh lá cây.

0

điều này phù hợp với tôi. tất cả đều có nền.

final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.ListRow)); 

builder.setIcon(android.R.drawable.ic_dialog_info).setTitle("welcome") 
     .setMessage("...") 
     .setPositiveButton("login", new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) 
      { 
       Intent intent = new Intent(HomeActivity.this, LoginActivity.class); 
       startActivity(intent); 
      } 
     }).setNegativeButton("register", new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) 
      { 
       Intent intent = new Intent(getApplicationContext(),RegisterActivity.class); 
       startActivity(intent); 
      } 
     }).show(); 
0

Xác định phong cách đối thoại với Theme.AppCompat.Dialog.Alert như mẹ:

<style name="AlertDialog" parent="Theme.AppCompat.Dialog.Alert"> 
    <item name="android:background">@color/green</item> 
    ... 
</style> 

Nguồn: http://www.materialdoc.com/alerts/

Các vấn đề liên quan