How to remove a name from DialogFragment?

I am using DialogFragment in my project and I will disable Title using

 getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 

but my dialogue has become crooked. I want to leave the dialog as is and just delete the Title. How can i do

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ff2d35ff"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginRight="39dp" android:layout_marginLeft="39dp" android:layout_gravity="center_horizontal" android:background="#ff6cff23"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ItemName" android:id="@+id/itemName" android:layout_weight="1" android:background="#ffd861ff"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ItemPrice" android:id="@+id/itemPrice" android:layout_weight="1" android:background="#ff2ff8ff"/> </LinearLayout> <ImageView android:layout_width="100dp" android:layout_height="100dp" android:id="@+id/itemImage" android:layout_gravity="center_horizontal"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="some test" android:id="@+id/textView9" android:layout_gravity="center_horizontal"/> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal" android:background="#ffffff2c"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="-" android:id="@+id/itemMinus" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="1" android:id="@+id/textView11" android:layout_weight="1" android:gravity="center_horizontal"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="+" android:id="@+id/itemPlus"/> </LinearLayout> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:gravity="center_horizontal"> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/itemAdd" android:src="@drawable/positive" android:background="@android:color/transparent"/> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/itemCancel" android:src="@drawable/negative" android:background="@android:color/transparent"/> </LinearLayout> 

I realized that when I remove the Title dialog, match_parent cannot be match_parent

+6
source share
3 answers

you must override the onCreateDialog method in your aperture class.

 @Override public Dialog onCreateDialog(final Bundle savedInstanceState) { RelativeLayout root = new RelativeLayout(getActivity()); root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(root); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE)); dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); return dialog; } 
+11
source

I usually override onCreate in my subclass of DialogFragment and call setStyle(STYLE_NO_TITLE, 0);

 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(STYLE_NO_TITLE, 0); } 

Here you can find the documentation for setStyle . The documentation for STYLE_NO_TITLE says:

Style for setStyle (int, int): do not include header area.

+13
source

You can implement it easier, for example, below the code -

 Dialog dialog = new Dialog(mContext, android.R.style.Theme_Black_NoTitleBar); 

or

Dialog dialog = new Dialog(mContext, android.R.style.Theme_Black_NoTitleBar_Fullscreen);

0
source

Source: https://habr.com/ru/post/984002/


All Articles