Android Dialog: Removing title bar
I have a weird behavior I can't pinpoint the source of.
I have my app with the classic
requestWindowFeature(Window.FEATURE_NO_TITLE);
to remove the title/status bar.
I then create a Dialog box to allow the user to enter information (name etc)
With a physical keyboard, no problem but when I use the virtual keyboard I have a strange behavior:
each time I hit a key on the virtual key board the title/status bar reappears pushing all the keyboard layout around then vanishes again (just like the animation of when I start the application)
here is some code :
dialog = new Dialog(context);
dialog.setContentView(R.layout.logindialog);
dialog.setTitle("Login:");
WindowManager.LayoutParams a = dialog.getWindow().getAttributes();
// dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
a.dimAmount = 0;
dialog.getWindow().setAttributes(a);
dialog.setCancelable(true);
dialog.getWindow().setLayout(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
and then
dialog.show();
I tried
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
but it crashes my app.
here is the xml
<TextView android:id="@+id/LoginText"
android:gravity="fill"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login:">
</TextView>
<EditText android:id="@+id/LoginEdit"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="jason"
android:layout_width="200sp"/>
<TextView android:id="@+id/PasswordText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:">
</TextView>
<EditText android:id="@+id/PasswordEdit"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="welcome"
android:layout_width="200sp"
android:password="true"/>
<LinearLayout
android:id="@+id/test2"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button android:id="@+id/LoginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Login" />
<Button android:id="@+id/CreateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Create" />
<Button android:id="@+id/CancelLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Cancel" />
</LinearLayout>/>
use,
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before
dialog.setContentView(R.layout.logindialog);
create new style in styles.xml
<style name="myDialog" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
then add this to your manifest:
<activity android:name=".youractivity" android:theme="@style/myDialog"></activity>
All the above answer not working for me for AppCompatDialog
If you are using AppCompatDialog try this
Important note: Set this before calling setContentView.
dialog.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
create your XML which is shown in dialog here it is activity_no_title_dialog
final Dialog dialog1 = new Dialog(context);
dialog1.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog1.setContentView(R.layout.activity_no_title_dialog);
dialog1.show();
With next variant I have no reaction:
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before
dialog.setContentView(R.layout.logindialog);
So, I try to use next:
dialog.supportRequestWindowFeature(Window.FEATURE_NO_TITLE); //before
dialog.setContentView(R.layout.logindialog);
This variant work excellent.