【问题标题】:How to remove the title in Dialog?如何删除对话框中的标题?
【发布时间】:2011-11-29 20:15:57
【问题描述】:

我使用下面的代码创建了一个 Activity 作为一个对话框,我把它放在我的清单中。但问题是它有标题栏,我该如何删除它?

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

【问题讨论】:

标签: android dialog


【解决方案1】:

如果对话框 ....................

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

res-->values-->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>

【讨论】:

  • 你要明白,只有 Activity 和 Dialog 行为相同。它既不是 Dialog 也不是 Alertdialog
  • false 应该设置为 true
【解决方案2】:

在创建对话框时使用此代码:

requestWindowFeature(Window.FEATURE_NO_TITLE);

【讨论】:

    【解决方案3】:

    使用此代码

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

    【讨论】:

      【解决方案4】:

      这对我有用

      <?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);
      

      【讨论】:

      • 两个答案都已经在上面发布了,您只需将它们组合成一个答案
      【解决方案5】:
      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();
                              }
                          });
                      }
                  });
              }
          };
      

      【讨论】:

        【解决方案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>
        

        【讨论】:

          【解决方案7】:

          从扩展 ActionBarActivityAppcompatActivity 的带有对话框主题的 Activity 中删除标题栏

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

          【讨论】:

            【解决方案8】:

            对于那些正在使用 AppCompatActivity 的人来说,上面的答案可能不起作用。

            试试这个

            supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
            immediately before setContentView(R.layout.my_dialog_activity);
            

            【讨论】:

              【解决方案9】:

              它对我有用:

              在我的自定义对话框活动的 onCreate() 中:

              @Override
              protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
                  setContentView(R.layout.activity_alert_dialogue);
              
                  //your code....
              
              }
              

              清单:

              <activity android:name=".AlertDialogue"
                          android:theme="@style/AlertDialogNoTitle">
              </activity>
              

              风格:

              <style name="AlertDialogNoTitle" parent="Theme.AppCompat.Light.Dialog">
                      <item name="android:windowNoTitle">true</item>
              </style>
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2015-04-24
                • 2012-10-28
                • 1970-01-01
                • 2011-09-09
                • 1970-01-01
                • 2012-01-08
                相关资源
                最近更新 更多