How to display Dialog Fragment on FullScreen? [duplicate] - android

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

Related

Click behind fragment when DialogFragment is shown

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.

DialogFragment show only the Buttons even the layout has more

As the picture show the DialogFragment It´s all white except for the Buttons. I have tried all kinds of layout parrams and ConstraintLayout settings but the white background feels like it´s some z-order thing,
Please advice
This is what the ANdroid Studio layout editor look likes
My xml:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:srcCompat="http://schemas.android.com/tools"
android:id="#+id/place_search_dialog"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:visibility="visible">
<ImageView
android:id="#+id/place_search_dialog_header_image_IV"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:contentDescription=""
android:scaleType="centerCrop"
app:layout_constraintBottom_toTopOf="#+id/guideline478"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
srcCompat:src="#drawable/place_picker_dialog_nobackground"/>
<Button
android:id="#+id/btn_place_dialog_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:padding="10dp"
android:text="#string/cancel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/btn_place_dialog_ok"/>
<Button
android:id="#+id/btn_place_dialog_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:padding="10dp"
android:text="#string/ok"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/btn_place_dialog_cancel"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"/>
<android.support.constraint.Guideline
android:id="#+id/guideline355"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.66"/>
<ImageView
android:id="#+id/imageView_street"
android:layout_width="74dp"
android:layout_height="48dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="#+id/btn_place_dialog_cancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.348"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/place_search_dialog_header_image_IV"
app:layout_constraintVertical_bias="0.581"
app:srcCompat="#drawable/avatar"/>
<android.support.constraint.Guideline
android:id="#+id/guideline478"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.28"/>
</android.support.constraint.ConstraintLayout>
UPDATE
This is the DialogFragment
public class GooglePlaceDetailsDialogFragment extends DialogFragment {
private View mRootView;
private BasePlace place;
private Unbinder unbinder;
RequestResponse requestResponse;
private PlaceDetails placeDetails;
public interface ShowPlaceListener {
void onShowPlace(BasePlace item);
}
private ShowPlaceListener mShowPlaceListener;
public static GooglePlaceDetailsDialogFragment newInstance(BasePlace item) {
GooglePlaceDetailsDialogFragment fragment = new GooglePlaceDetailsDialogFragment();
fragment.setPlace(item);
return fragment;
}
// Called to do initial creation of a fragment. This is called after onAttach and before onCreateView
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
mShowPlaceListener = (ShowPlaceListener) getTargetFragment();
} catch (ClassCastException e) {
throw new ClassCastException("Calling fragment must implement Callback ShowPlaceListener");
}
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container,
#Nullable Bundle savedInstanceState) {
mRootView = inflater.inflate(R.layout.dialog_fragment_show_google_place_details, container);
ImageView imageViewStreet = mRootView.findViewById(R.id.imageView_street);
// Just unpack the details to make it smoother
this.requestResponse = place.requestResponse;
this.placeDetails = place.requestResponse.placeDetails;
unbinder = ButterKnife.bind(this, mRootView);
getDialog().setTitle("lkjkjlkj ");
if (placeDetails.url.equals("")) {
if (LogManager.isDebugable()) {
Picasso.with(getActivity()).setIndicatorsEnabled(true);
}
Picasso.with(getActivity())
.load(R.drawable.anon_user_48dp)
.transform(new CircleTransformation())
.into(imageViewStreet);
} else {
if (LogManager.isDebugable()) {
Picasso.with(getActivity()).setIndicatorsEnabled(true);
}
Picasso.with(getActivity())
.load(placeDetails.url)
.transform(new CircleTransformation())
.into(imageViewStreet);
}
return mRootView;
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
#Override
public void onResume() {
super.onResume();
}
#OnClick(R.id.btn_place_dialog_ok)
public void onSearchClicked() {
if (mShowPlaceListener != null) {
mShowPlaceListener.onShowPlace(place);
}
dismiss();
}
#OnClick(R.id.btn_place_dialog_cancel)
public void onCancelClicked() {
dismiss();
}
private void setPlace(BasePlace place) {
this.place = place;
}
#Override
public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
}
}
This is the creation
GooglePlaceDetailsDialogFragment dialog = GooglePlaceDetailsDialogFragment.newInstance(item);
dialog.setTargetFragment(this, 0);
DialogUtils.showDialogFragment(getFragmentManager(), dialog);
Util..
public class DialogUtils {
private static String showDialogFragment(FragmentManager fragmentManager, DialogFragment dialogFragment,
String fragmentTag, boolean onlyIfNotDuplicate) {
// If only showing non duplicates dialogs, make sure the fragment isn't already in the manager
boolean doesFragmentExist = fragmentManager.findFragmentByTag(fragmentTag) != null;
if (!(onlyIfNotDuplicate && doesFragmentExist)) {
dialogFragment.show(fragmentManager, fragmentTag);
}
return fragmentTag;
}
public static String showDialogFragment(FragmentManager fragmentManager, DialogFragment dialogFragment,
boolean onlyIfNotDuplicate) {
return showDialogFragment(fragmentManager, dialogFragment, generateFragmentTag(dialogFragment), onlyIfNotDuplicate);
}
private static String showDialogFragment(FragmentManager fragmentManager, DialogFragment dialogFragment,
String fragmentTag) {
return showDialogFragment(fragmentManager, dialogFragment, fragmentTag, true);
}
public static String showDialogFragment(FragmentManager fragmentManager, DialogFragment dialogFragment) {
return showDialogFragment(fragmentManager, dialogFragment, generateFragmentTag(dialogFragment));
}
private static String generateFragmentTag(Fragment fragment) {
return fragment.getClass().getName();
}
}
ok when I replace the srcCompat:src= with app:srcCompat=` the images show, Strange that AS did not complain abut this typo

Trying to set an OnClickListener on a button in a DialogFragment

I am trying to set an onclicklistener for a button in my dialog. However, when my dialog loads, it crashes, saying Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference on the line date = (Button) v.findViewById(R.id.DateButton);. I have the following dialog:
public class EventsDialog extends DialogFragment {
private Button date;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.event_dialog, container, false);
date = (Button) v.findViewById(R.id.DateButton);
// set onclicklistener
date.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
OpenDate();
}
});
return v;
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.event_dialog, null));
return builder.create();
}
public void OpenDate() {
DatePickerFragment newFragment = new DatePickerFragment();
newFragment.show(getActivity().getSupportFragmentManager(), "datepicker");
}
}
And the layout:
android.support.constraint.ConstraintLayout 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"
android:layout_width="#dimen/mr_controller_volume_group_list_max_height"
android:layout_height="match_parent"
android:background="#dfdfdf"
android:orientation="vertical">
<TextView
android:id="#+id/eventsHeader"
android:layout_width="0dp"
android:layout_height="46dp"
android:background="#color/colorAccent"
android:text="Add a New Event!"
android:textAppearance="#style/TextAppearance.AppCompat.Display1"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:textColor="#android:color/white" />
<EditText
android:id="#+id/EventName"
android:layout_width="match_parent"
android:layout_height="46dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="7dp"
android:hint="Event Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/eventsHeader" />
<Button
android:id="#+id/DateButton"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:text=""
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/EventName" />
<Button
android:id="#+id/TimeButton"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:text=""
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/DateButton" />
<EditText
android:id="#+id/EventLocation"
android:layout_width="0dp"
android:layout_height="46dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:hint="Location"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/TimeButton" />
<EditText
android:id="#+id/EventDetails"
android:layout_width="0dp"
android:layout_height="186dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Details"
android:inputType="textMultiLine"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/EventLocation" />
<ImageButton
android:id="#+id/SaveButtonEvents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/EventDetails"
app:srcCompat="#android:drawable/ic_menu_save" />
</android.support.constraint.ConstraintLayout>
you are inflating your layout two times. Do inflate it in onCreateDialog() method and do something like below and remove onCreateView() method:
#NonNull
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view = getActivity().getLayoutInflater().inflate(R.layout.event_dialog, null,false);
builder.setView(view);
builder.setTitle("Your Title");
date = (Button) view.findViewById(R.id.DateButton);
// set onclicklistener
date.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
OpenDate();
}
});
return builder.create();
I have used DialogFragment on my project, and I had wrote it by
the following way.
Here is my AlertDFragment.Java
public class AlertDFragment extends DialogFragment {
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
// Set Dialog Icon
.setIcon(R.drawable.androidhappy)
// Set Dialog Title
.setTitle("Alert DialogFragment")
// Set Dialog Message
.setMessage("Alert DialogFragment Tutorial")
// Positive button
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do something else
}
})
// Negative Button
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do something else
}
}).create();
}
}
And the output is,

AlertDialog Layout below the buttons

I have my own layout for an AlertDialog, and if I use setPositiveButton everything works. But when i use setItems, my layout is shown below the item buttons.
How can I show my custom layout on top?
Here is my code:
private void selectImage(){
final CharSequence[] items = { TAKE_PICTURE, FROM_GALLERY, CANCLE};
AlertDialog.Builder builder = new AlertDialog.Builder(Add_Object.this);
LayoutInflater inflater = this.getLayoutInflater();
View content = inflater.inflate(R.layout.alert_dialog, null);
builder.setView(content);
((TextView) content.findViewById(R.id.dialogTitle)).setText(R.string.addPictureTitle);
builder.setItems(items, new DialogInterface.OnClickListener(){
#Override
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals(TAKE_PICTURE)) {
captureImage();
} else if (items[item].equals(FROM_GALLERY)) {
chooseFromGallery();
} else if (items[item].equals(CANCLE)) {
dialog.dismiss();
}
}
});
builder.show();
}
}
And my layout:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/dialogTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:textSize="25sp"
android:textColor="#color/main_color"/>
<View
android:layout_width="match_parent"
android:id="#+id/dialogDivider"
android:layout_below="#id/dialogTitle"
android:layout_height="2dp"
android:background="#color/main_color" />
<TextView
android:id="#+id/dialogText"
android:layout_below="#+id/dialogDivider"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textSize="18sp"
android:textColor="#color/darkgrey"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Thanks in advance.
You can use builder.setCustomTitle(content) instead of setView(content), but this will add a separator line between your layout and the item buttons...
EDIT:
As an alternative, you can add the list to your custom layout, e.g. with an TextView like this:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/take_picture"
android:layout_below="#id/dialogText"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textSize="26sp"
android:onClick="takePicture"/>
and define the takePicture method in your MainActivity:
public void takePicture(View view) {
Log.i("MainActivity", "take picture");
//cancel the dialog
dialog.dismiss();
}
the dialog is saved in a class variable, and initialized in selectImage():
private void selectImage(){
final CharSequence[] items = { "TAKE_PICTURE", "FROM_GALLERY", "CANCLE"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
View title = inflater.inflate(R.layout.alert_dialog, null);
builder.setView(title);
((TextView) title.findViewById(R.id.dialogTitle)).setText("picture title");
((TextView) title.findViewById(R.id.take_picture)).setText(items[0]);
//init dialog
dialog = builder.create();
dialog.show();
}

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

Categories

Resources