Имеется прозрачный DialogFragment.
public class TempFragment extends DialogFragment {
static TempFragment newInstance() {
TempFragment dialogFragment = new TempFragment();
return dialogFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_block_dialog, container, false);
return v;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
final Drawable drawable = new ColorDrawable(-15108398);
drawable.setAlpha(200);
dialog.getWindow().setBackgroundDrawable(drawable);
dialog.getWindow().requestFeature(android.view.Window.FEATURE_NO_TITLE);
return dialog;
}
@Override
public void onStart() {
super.onStart();
getDialog().getWindow().setLayout(1000, 1500);
}
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/block_dialog_layout"
style="@android:style/Theme.Dialog"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp"
android:text="@string/hello_blank_fragment"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Click"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="@+id/show2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Click"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
В этих строках:
getDialog().getWindow().setLayout(1000, 1500);
я хардкодингом расширяю DialogFragment
, так как этого не сделать он получается очень узкий. Как же правильно расширить DialogFrgment
(не хардкодно) - чтобы он получился такой же как в этом коде, то есть занимал почти весь экран, но оставляя рамки, как и пристало нормальному Диалогу (с Title)).
Может делать так , как сам DialogFragment
расширяет (когда Title не удаляется пользователем)?
Мне он нужен без титла, я его удаляю dialog.getWindow().requestFeature(android.view.Window.FEATURE_NO_TITLE);
при этом Dialog сужается по максимуму...