2016-04-24 165 views
0

我在我的項目中使用了一個自定義對話框,它在單獨的xml文件中創建,並且我將主窗口着色爲藍色, ,但主標題仍然是默認的白色。如何在android studio中自定義Dialog頭文件?

有沒有辦法改變標題的字體顏色,大小和背景?

我可以在標題中改變文本的唯一內容嗎?

XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="15dp" 
    android:paddingRight="15dp" 
    android:background="#3edfbc" 
    android:orientation="vertical"> 


    <TextView 
     android:id="@+id/textaligmentManager_loader_textview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="#ffffff" 
     android:text="Initlizing Wifi" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <com.github.ybq.android.spinkit.SpinKitView xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/barcodeScanning_spinkit" 
     style="@style/SpinKitView.Large.FoldingCube" 
     android:layout_width="80dp" 
     android:layout_height="80dp" 
     android:layout_below="@+id/textaligmentManager_loader_textview" 
     android:padding="20dp" 
     android:layout_centerHorizontal="true" 
     app:SpinKit_Color="#ffffff" /> 


</RelativeLayout> 

對話框:

Dialog dialog = new Dialog(Scanning_Barcode_Activity.this); 
     dialog.setContentView(R.layout.aligment_manager_loader_layout); 
     dialog.setTitle("Loading"); 
     dialog.setCancelable(false); 

     //set up text 
     loaderScreenMainText = (TextView) dialog.findViewById(R.id.textaligmentManager_loader_textview); 
     loaderScreenMainText.setText("Loading Wifi"); 


     //progressBar = (ProgressBar) dialog.findViewById(R.id.barcodeScanning_spinkit); 
     //DoubleBounce doubleBounce = new DoubleBounce(); 
     //progressBar.setIndeterminateDrawable(doubleBounce); 


     //now that the dialog is set up, it's time to show it 
     dialog.show(); 

回答

0

在佈局本身包含標題部分這樣的方式設計您的自定義佈局。然後跳到下面的代碼:

dialog.setTitle("Loading"); 

而是添加此聲明:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 

您還可以使用AlertDialog。在這種情況下,requestWindowFeature()方法不是必需的。

android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(Scanning_Barcode_Activity.this); 
LayoutInflater inflater = LayoutInflater.from(Scanning_Barcode_Activity.this); 
View customView = inflater.inflate(your_layout, null); 
builder.setCancelable(false); 
loaderScreenMainText = (TextView) customView.findViewById(R.id.textaligmentManager_loader_textview); 
loaderScreenMainText.setText("Loading Wifi"); 
builder.setView(customView); 
AlertDialog dialog = builder.create(); 
dialog.show(); 
+0

它仍然會顯示一個標題區域..只是沒有文本...這意味着它仍然在屏幕上顯示一個白色區域 –

+0

添加此語句:dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); –

+0

你不能在這個階段做到這一點,因爲ive已經在創建視圖上設置了內容(它不起作用...) –

0

您可以使用AlertDialog,它是Dialog類的子類。在這裏您可以定義包含標題,正文和按鈕等所有內容的自定義佈局。沒有額外的標題部分會出現。這裏是一個演示:

AlertDialog.Builder builder = new AlertDialog.Builder(Scanning_Barcode_Activity.this); 
    builder.setCancelable(false); 
    LayoutInflater inflater = LayoutInflater.from(Scanning_Barcode_Activity.this); 
    View dialogView = inflater.inflate(R.layout.aligment_manager_loader_layout, null); 
    TextView loaderScreenMainText = (TextView) dialogView.findViewById(R.id.textaligmentManager_loader_textview); 
    loaderScreenMainText.setText("Loading Wifi"); 
    builder.setView(dialogView); 
    AlertDialog dialog = builder.create(); 
    dialog.show(); 
0

有許多時尚的開源庫可用於定製頭部分。

在這裏我分享我的新開發的開放源碼庫:PanterDialog

希望它會幫助你。

相關問題