2012-03-15 29 views
5

Tôi đã tạo chủ đề tùy chỉnh cho các hộp thoại trong ứng dụng Android của mình và tôi đã lên kế hoạch ghi đè bố cục được sử dụng cho tiêu đề hộp thoại. Tôi thấy rằng trong tiêu chuẩn android Theme có thuộc tính này giống như thuộc tính cần sửa đổi.Bố cục tiêu đề hộp thoại ghi đè trong Android

<item name="dialogTitleDecorLayout">@layout/dialog_title</item> 

Nhưng khi tôi cố gắng để ghi đè lên nó trong tôi Theme

<style name="Theme.Dialog.MyDialog" parent="android:Theme.Dialog"> 
    <item name="android:windowBackground">@android:color/black</item> 
    <item name="android:dialogTitleDecorLayout">@layout/my_dialog_title</item> 
</style> 

Tôi thấy các lỗi sau:

No resource found that matches the given name: attr 'android:dialogTitleDecorLayout'

Tại sao tôi không thể thay đổi nó và làm thế nào tôi có thể biết được thuộc tính có thể được thay đổi và không?

+0

bạn có thể hiển thị các tập tin xml đầy đủ cho phong cách? Có thể bạn đang thiếu lược đồ xml cho android ở đó? – Genry

Trả lời

1

Không thể ghi đè mục đó như thế này. Bạn phải tùy chỉnh hộp thoại với bố cục được yêu cầu và sau đó trong bố cục, bạn phải áp dụng chủ đề ở đây cho những gì bạn yêu cầu.

dialog_title.xml 

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/text" 
    android:text="@string/tell_a_friend" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="8dip" 
    android:paddingTop="12dip" 
    android:paddingBottom="12dip" 
    style="@style/bigTextWhite" /> 

</LinearLayout> 

// đây là phương pháp nơi thoại của bạn xuất hiện trong sự kiện onclick nút

public void onClickHelp(View v) { 
    final Dialog duDialog = new Dialog(this); 
    duDialog.setContentView(R.layout.data_usage); 
    duDialog.getWindow().setBackgroundDrawableResource(R.color.title_text); 

    duDialog.setTitle("Data Usage"); // I would like to set the color and add button here 
    ListView data = (ListView) duDialog.findViewById(R.id.DataUsage); 
    duCursor = Data.getAll(db); 
    startManagingCursor(duCursor); 
    duAdapter = new DataAdapter(duCursor); 
    data.setAdapter(duAdapter); 
    duDialog.show(); 

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