Click behind fragment when DialogFragment is shown - android

I need to have access for click on my behind fragment ( such as click on a button ) when DialogFragment is shown.
But when I click outside of DialogFragment, this will dismiss.
Used code to show DialogFragment:
FragmentManager fragmentManager = getFragmentManager();
MyDialogMapFragment dialogFragment = new MyDialogMapFragment();
dialogFragment.show( fragmentManager, "" );
MyDialogMapFragment Class:
public class MyDialogMapFragment extends DialogFragment {
private Activity mActivity;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.dialog_map_info, container, false);
return rootView;
}
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = new Dialog(getActivity(), R.style.DialogMap);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_map_info);
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.BOTTOM;
dialog.getWindow().setAttributes(lp);
return dialog;
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof Activity) {
mActivity = (Activity) context;
}
}
}
dialog_map_info.xml Layout:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="90dp"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<RelativeLayout
android:id="#+id/mainFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:clickable="true"
android:focusable="true"
android:background="#drawable/background_map_info">
<ProgressBar
android:id="#+id/progress_loader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
style="?android:attr/progressBarStyle" />
<TextView
android:id="#+id/itemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Test" />
</RelativeLayout>
</FrameLayout>
Below image will describe what is my layout:

If you need to detect a click the while a dialog is being shown it would be easier to set an onClickListener to a view on your dialog.
When you the onClickListener is called then you can either perform a click on the button button.perfomClick() or even better call the function that the button onClickListener calls.

Related

getHeight() doesn't get the height of the layout

I'm going to use dialog fragments.
There is an item called writing_comment_item.xml in the dialogfragment, and I want to set the height of 5 items.
I used the inflate() function, I used getHeight() to get the layout.
But as a result of debugging, the height is 0 no matter how much.
I tried in onCreate(). Also tried onCreateView() as well.
But the result was the same
What should I do?
writing_comment_item.xml
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".fragment.WritingCommentDialogFragment">
<EditText
android:id="#+id/comment_edit"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center_vertical"
android:drawableLeft="#drawable/ic_bullet_point"
android:drawablePadding="5dp"
android:layout_marginHorizontal="10dp"
android:background="#null"
android:textSize="15sp"
android:inputType="text"
android:maxLines="1"
android:maxLength="22"
android:imeOptions="actionNext"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
</EditText>
</androidx.constraintlayout.widget.ConstraintLayout>
WCDialogFragment.java
public class WritingCommentDialogFragment extends DialogFragment implements CommentModel.EditInputListener {
OnBackPressedCallback callback;
LinearLayout commentContainer; // input layout
private final List<Comment> comments = new ArrayList<>();
private LayoutInflater layoutInflater;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_writing_comment_dialog, container, false);
bindViews(view);
addCommentItem();
return view;
}
private void bindViews(View v) {
commentContainer = v.findViewById(R.id.container);
layoutInflater = LayoutInflater.from(getContext());
}
#NonNull
#Override
public Dialog onCreateDialog(#Nullable Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.setCanceledOnTouchOutside(false);
return dialog;
}
#Override
public void onResume() {
super.onResume();
setDialogSize();
}
private void setDialogSize() {
View v = LayoutInflater.from(getContext()).inflate(R.layout.writing_comment_item, null, false);
int h = v.getHeight() * 5;
getDialog().getWindow().setLayout(1000, h);
}
}
EDITED
private void setDialogSize() {
View v = LayoutInflater.from(getContext()).inflate(R.layout.writing_comment_item, null, false);
v.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
v.getMeasuredHeight();
int h = v.getMeasuredHeight() * 5;
getDialog().getWindow().setLayout(1000, h);
}
ADDED PIC
The mistake here is trying to get the height of a view that hasn't been added to the layout hierarchy. When you call
inflate(R.layout.writing_comment_item, null, false);
with attachToRoot being false, you are specifying that you don't want it to be added to the hierarchy yet so the system never measures the view.
You could instead call View.measure(int, int) yourself and then use View.getMeasuredHeight(). This question covers that in a bit more detail - Measuring a view before rendering it

How to display Dialog Fragment on FullScreen? [duplicate]

This question already has answers here:
How to set dialog to show in full screen? [closed]
(5 answers)
Closed 2 years ago.
I have a custom DialogFragment and it displays only half the height. Width is fine.I set height="match_parent" in my layout.My root Element is RelativeLayout. I do not know how to fix
height problem.
Here is java class.
public class DefeatDialog extends DialogFragment {
public interface DialogListener {
void onDialogPositiveClick(DialogFragment dialog);
}
public DefeatDialog() {
}
DialogListener mListener;
DefeatAlertBinding binding;
#Override
public void onAttach(#NonNull Context context) {
super.onAttach(context);
try {
// Instantiate the NoticeDialogListener so we can send events to the host
mListener = (DialogListener) context;
} catch (ClassCastException e) {
// The activity doesn't implement the interface, throw exception
throw new ClassCastException(context.toString()
+ " must implement NoticeDialogListener");
}
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.defeat_alert, null, false);
builder.setView(view);
binding = DefeatAlertBinding.bind(view);
binding.startAgain.setOnClickListener((v -> {
mListener.onDialogPositiveClick(DefeatDialog.this);
}));
final AlertDialog dialog = builder.create();
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
dialog.show();
return dialog;
}
}
How can i fix that?Here my xml file.Here is my layout for DialogFragment. it does not display on full screen.Also not all part of xml displayed.
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/red"
android:orientation="vertical">
<ImageView
android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="#drawable/line_defeat"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.057"
tools:layout_editor_absoluteX="0dp" />
<ImageView
android:id="#+id/image"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/icon_defeat"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/line"
app:layout_constraintVertical_bias="0.036" />
<TextView
android:id="#+id/textView_1"
android:layout_width="400dp"
android:layout_height="80dp"
android:gravity="center"
android:text="#string/defeat"
android:textColor="#color/dark"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/image"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textView_2"
android:layout_width="400dp"
android:layout_height="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.454"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView_1"
app:layout_constraintVertical_bias="0.131" />
<Button
android:id="#+id/start_again"
android:layout_width="200dp"
android:layout_height="40dp"
android:background="#drawable/button_win_defeat"
android:text="#string/button_defeat_win"
android:textColor="#color/colorWhite"
android:textSize="17sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView_2"
app:layout_constraintVertical_bias="0.024" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
Here is my layout for DialogFragment. it does not display on full screen.Also not all part of xml displayed.
If you are sure that your XML's root is match_parent to match_parent, this should solve your problem, replace your onCreateDialog with below
#NonNull
#Override
public Dialog onCreateDialog(#Nullable Bundle savedInstanceState) {
final Dialog dialog = new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
return dialog;
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.defeat_alert, container, false);
binding = DefeatAlertBinding.bind(view);
binding.startAgain.setOnClickListener((v -> {
mListener.onDialogPositiveClick(DefeatDialog.this);
}));
return v;
}
#Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null) {
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setLayout(width, height);
}
}

Full Screen loading dialog won't go completely full screen

I am trying to use an image as the background for my loading dialog. The dialog is supposed to be full screen, but all I get is this...
How can I make the dialog fill the screen so I don't have that white border?
Heres my layout xml...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/locating"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/kumalocating">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="LOCATING OFFERS IN YOUR AREA"
android:textAlignment="center"
android:textAppearance="#style/TextAppearance.AppCompat.Large"
android:textColor="#android:color/white"
android:textSize="30sp"
android:textStyle="bold" />
</RelativeLayout>
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminateDrawable="#drawable/loader_1" />
</RelativeLayout>
and my class...
public class SpinnerDialog extends DialogFragment {
private static String message;
public SpinnerDialog() {
// use empty constructors. If something is needed use onCreate's
message = null;
}
public static SpinnerDialog spinnerWithCustomMessage(String msg) {
SpinnerDialog d = new SpinnerDialog();
message = msg;
return d;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fill_dialog, container);
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
Code to show:
spinnerDialog = SpinnerDialog.spinnerWithCustomMessage(getString(R.string.lo‌​ading_message));
spinnerDialog.show(getFragmentManager(), null);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL,android.R.style.Theme_Black_NoTitleBar_Fullscreen);
}
Add above code inside the SpinnerDialog class!
Use this code in the Java class.
Dialog mydialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
Edit
Add the following line in the SpinnerDialog.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, android.R.style.Theme_Translucent_NoTitleBar);
}

Dimmed Background of PopupWindow excludes Toolbars / Action Bars

I use the following codes to create a PopupWindow with dim background by clicking a menu item in Toolbar:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.btn_1:
Log.i(TAG, "Clicked Button 1");
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup_window, null);
final PopupWindow popupWindow = new PopupWindow(popupView, Toolbar.LayoutParams.MATCH_PARENT, Toolbar.LayoutParams.MATCH_PARENT);
Button btnDismiss = (Button)popupView.findViewById(R.id.btn_dismiss);
btnDismiss.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
However, I want to the dim background to exclude the action bars / toolbars. How can I achieve it?
The layout of the PopupView is as follow:
<?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="match_parent">
<RelativeLayout
android:id="#+id/bac_dim_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C0000000"
android:visibility="visible" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="1dp"
android:background="#android:color/darker_gray">
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="20dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="It's a PopupWindow" />
<Button
android:id="#+id/btn_dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dismiss" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
if you want popup window to display with dim background except ToolBar/ActionBar
here i tried setting position of popup window. fetch statusbar & navigation bar height & set Y position to the popup
int actionBarHeight = 0;
View popupView = LayoutInflater.from(getActivity()).inflate(R.layout.popup_, null);
final PopupWindow popupWindow = new PopupWindow(popupView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
actionBarHeight = getNavigationBarHeight(getActivity(), Configuration.ORIENTATION_PORTRAIT);
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
actionBarHeight = actionBarHeight + getResources().getDimensionPixelSize(resourceId);
}
Button btnDismiss = (Button) popupView.findViewById(R.id.btn_dismiss);
btnDismiss.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
popupWindow.showAsDropDown(popupView, 0, actionBarHeight);
Another way to display popup as you said in comment.Below mentioned you can try
Take one hidden control(TextView) in layout which will be aligned to top. Take the location of the TextView & assigned Y position to popup window
public class MyPopupTest extends Fragment{
public static final String TAG = "MyPopupTest";
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.home_screen_slider, container, false);
}
#Override
public void onViewCreated(final View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.findViewById(R.id.btnSelect).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showPopup(view);
}
});
}
public void showPopup(View view) {
View popupView = LayoutInflater.from(getActivity()).inflate(R.layout.popup_, null);
final PopupWindow popupWindow = new PopupWindow(popupView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
Button btnDismiss = (Button) popupView.findViewById(R.id.btn_dismiss);
btnDismiss.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
int[] locationOfHiddenTextView = new int[2];
view.findViewById(R.id.hiddenTopTextView).getLocationOnScreen(locationOfHiddenTextView);
//Give Position as a start point for popup
popupWindow.showAsDropDown(popupView, 0, locationOfHiddenTextView[1]);
}
}
XML File of the fragment which is goint to display
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relative_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffc699">
<TextView
android:id="#+id/hiddenTopTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:visibility="gone" />
<Button
android:id="#+id/btnSelect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Popup" />
</RelativeLayout>
I have a solution, but I only test with DialogFragment, not sure it works with dialog or not. I will post it anyway:
1. create your own class which extends DialogFragment.
2. create xml file with your designed dim color:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80000000" // your designed dim color
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/goto_dialog_title"
android:textColor="#android:color/white"
android:textSize="#dimen/km_25sp"/>
3. Override funcions in your DialogFragment:
private class MyDialog extends DialogFragment{
//override your onCreateView to show your xml here
//override onCreate to show dialog without border and without dim background
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_FRAME, 0);
}
// override to show dim background and avoid dimming actionbar
#Override
public void onResume() {
super.onResume();
int statusBarAndActionBarHeight = 200; //u should calculate yourself
Window window = getDialog().getWindow();
// set size to your dialog --> fullscreen size to show dim bg all screen except action bar and status bar
DisplayMetrics displaymetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
window.setLayout(displaymetrics.widthPixels, displaymetrics.heightPixels - statusBarAndActionBarHeight);
//margin top to avoid dim background above actionbar and status bar
WindowManager.LayoutParams p = window.getAttributes();
p.y = statusBarAndActionBarHeight;
getDialog().getWindow().setGravity(Gravity.TOP);
getDialog().getWindow().setAttributes(p);
}
}

Android, dialog_fragment. dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)

I'm using dialog fragment and everything is fine until I'm trying to remove title bar. There is a code:
Dialog XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#f0f0f0">
<GridView
android:id="#+id/gv_registration_avatars"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="#dimen/avatar_layout_margin"
android:columnWidth="100dp"
android:drawSelectorOnTop="true"
android:gravity="center"
android:numColumns="2"
android:stretchMode="columnWidth"
android:focusable="true"
android:clickable="true"
/>
<Button
android:id="#+id/dismiss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/avatar_layout_margin"
android:layout_marginRight="#dimen/avatar_layout_margin"
android:layout_below="#id/gv_registration_avatars"
android:text="Ok"
android:layout_gravity="right"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar_avatars"
android:layout_centerInParent="true"
android:visibility="gone"/>
DialogFragment class is :
public class AvatarPickDialogFragment extends DialogFragment {
private GridView mGridView;
private ProgressBar mProgressBar;
private GridViewAvatarAdapter mGridAdapter;
private ArrayList<String> mGridData;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.avatar_pick_dialog_fragment, container, false);
mGridView = (GridView) rootView.findViewById(R.id.gv_registration_avatars);
mProgressBar = (ProgressBar) rootView.findViewById(R.id.progressBar_avatars);
mGridData = new ArrayList<>();
mGridAdapter = new GridViewAvatarAdapter(getActivity(), R.layout.grid_item_avatar_layout, mGridData);
mGridView.setAdapter(mGridAdapter);
mProgressBar.setVisibility(View.VISIBLE);
String item;
for (int i = 0; i < 10; i++) {
item = new String();
item= new String("string");
mGridData.add(item);
}
mProgressBar.setVisibility(View.GONE);
mGridAdapter.setGridData(mGridData);
Button dismiss = (Button) rootView.findViewById(R.id.dismiss);
dismiss.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dismiss();
}
});
return rootView;
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// The only reason you might override this method when using onCreateView() is
// to modify any dialog characteristics. For example, the dialog includes a
// title by default, but your custom layout might not need it. So here you can
// remove the dialog title, but you must call the superclass to get the Dialog.
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
}
When I am using dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) title bar disappear, but my dialog window width changes to very short and I don't know why, because with title bar it is fine. Any suggestions?
You can try setting fragment width in fragment's onStart() method
#Override
public void onStart()
{
super.onStart();
if (getDialog() == null)
return;
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}

Categories

Resources