开发者

How to remove the title in Dialog?

I created an Activity as a dialo开发者_开发百科g using the code below which I put in my manifest. But the problem is it has Title bar, how can I remove it?

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


Use This Code

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


if Dialog ..............

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>


For Me following worked :

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


Use this code when creating a dialog:

requestWindowFeature(Window.FEATURE_NO_TITLE);


For those who are using AppCompatActivity, above answers may not work.

Try this

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


this is work for me

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

and this

requestWindowFeature(Window.FEATURE_NO_TITLE);


Remove Title Bar from Activity extending ActionBarActivity or AppcompatActivity with Dialog Theme

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


It work for me:

In the onCreate() of my custom Dialog Activity:

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

    //your code....

}

Manifest:

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

Style:

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


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();
                        }
                    });
                }
            });
        }
    };


I try requestWindowFeature(Window.FEATURE_NO_TITLE); but not working for me, if you are like me so do this : first Add the following code in your res/values/styles.xml:

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

Pass the theme to your dialog:

Dialog dialog = new Dialog(this, R.style.NoTitleDialog);

that's it very simple

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜