2011-10-03 50 views
8

我使用下面的代碼創建了一個活動作爲對話框,該代碼放置在我的清單中。但問題是它有標題欄,我該如何刪除它?如何刪除對話框中的標題?

android:theme="@android:style/Theme.Dialog" 
+0

這個什麼http://stackoverflow.com/questions/2644134/android-how-to-create- A-對話,而無需-一個標題? –

+0

對話框或alertdialog? –

+0

其行爲與對話框 – Leon

回答

7

如果對話框..............

Dailog dialog = new Dialog(MainActivity.this, R.style.mydialogstyle); 

RES - >值 - > mydialog.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="mydialogstyle" parent="android:style/Theme.Dialog"> 
     <item name="android:windowBackground">@null</item> 
     <item name="android:windowNoTitle">false</item> 
    </style> 
</resources> 
+0

相同的行爲您必須瞭解,它的行爲與Dialog具有相同的行爲。它既不是Dialog或Alertdialog – Leon

3

創建對話框時使用此代碼:

requestWindowFeature(Window.FEATURE_NO_TITLE); 
12

使用此代碼

final Dialog dialog = new Dialog(context); 
    dialog.getWindow(); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);  
    dialog.setContentView(R.layout.yourlayout); 
    dialog.show(); 
1

這對我來說

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<style name="mydialogstyle" parent="android:style/Theme.Dialog"> 
     <item name="android:windowBackground">@null</item> 
     <item name="android:windowNoTitle">true</item> 
    </style> 
</resources> 

和工作這

requestWindowFeature(Window.FEATURE_NO_TITLE); 
+0

這兩個答案已經張貼在你上面,只是將它們組合成一個答案 –

0
Handler _alerthandler = new Handler(); 
    Runnable _alertrunnable = new Runnable() { 
     @Override 
     public void run() { 
      // TODO Auto-generated method stub 
      ProfileActivity.this.runOnUiThread(new Runnable() { 
       public void run() { 
        // Create custom dialog object 
        final Dialog dialog = new Dialog(ProfileActivity.this); 
        // Include dialog.xml file 
        dialog.getWindow(); 
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
        dialog.setContentView(R.layout.alertbox); 
        TextView title = (TextView) dialog 
          .findViewById(R.id.AlertBox_Title); 
        title.setText(Appconstant.Toast_Title); 
        TextView text = (TextView) dialog 
          .findViewById(R.id.AlertBox_Msg); 
        text.setText(Appconstant.Toast_Msg); 
        dialog.show(); 

        Button declineButton = (Button) dialog 
          .findViewById(R.id.AlertBox_Ok); 
        // if decline button is clicked, close the custom dialog 
        declineButton.setOnClickListener(new OnClickListener() { 
         @Override 
         public void onClick(View v) { 
          // Close dialog 
          dialog.dismiss(); 
         } 
        }); 
       } 
      }); 
     } 
    }; 
+0

沒有標題(自定義對話框)..它工作正常。 – Vela

6

爲我工作下列:

<style name="MyActivityDialogTheme" parent="Base.Theme.AppCompat.Light.Dialog"> 
     <item name="android:windowNoTitle">true</item> 
     <item name="android:windowActionBar">false</item> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
    </style> 
1

從活動中刪除標題欄擴展ActionBarActivityAppcompatActivity與對話主題

<style name="Theme.MyDialog" parent="@style/Theme.AppCompat.Light.Dialog"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
</style> 
相關問題