having trouble while displaying an viewpager on popup window.
Wants to display multiple images on a viewpager which is actually a popup window. But unable to remove the side spaces of the window.
Viewpager
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" />
ImageView
<com.utility.TouchImageView
android:id="#+id/imgDisplay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
xmlns:android="http://schemas.android.com/apk/res/android" />
Try this It will remove side spaces and show your dialog as full screen(No side margins)
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Above line is the most important, don't miss to include it.
final Dialog dialog = new Dialog(getActivity(), R.style.DialogAnimation);
dialog.getWindow().getAttributes().windowAnimations =
R.style.DialogOpenAnimation;
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(true);
dialog.setContentView(R.layout.dialog_mediagallary);
ImageButton back_arrow = (ImageButton) dialog.findViewById(R.id.back);
viewPagerPhotoSlideShow = (ClickableViewPager) dialog.findViewById(R.id.photolist);
adapterPhotoViewPager = new AdaterViewPagerAllmeidagallary(getActivity(), pagerListItems);
viewPagerPhotoSlideShow.setAdapter(adapterPhotoViewPager);
viewPagerPhotoSlideShow.setCurrentItem(defaultPagerItemPosition);
back_arrow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
lp.gravity = Gravity.CENTER;
Window window = dialog.getWindow();
window.setAttributes(lp);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
If you are using Dialog containing viewpager
Either you can set the following style to that dialog as
dialog.setStyle(STYLE_NO_TITLE, R.style.DialogStyle);
DialogStyle
<style name="DialogStyle" parent="Base.Theme.AppCompat.Dialog">
<item name="android:windowMinWidthMajor">100%</item>
<item name="android:windowMinWidthMinor">100%</item>
</style>
Or you can canculate the screen width and pass that to the dialog width as
Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
popUpLayout = Globals.layoutInflater.inflate(R.layout.pop_up_layout,
null);
dialog.setContentView(popUpLayout);
dialog.getWindow().setLayout(Desired_Width, Desired_Hight);
dialog.show();
Related
I need to create a custom full-screen dialog with overlay background. Here is the image of the expected result:
I tried the below code but it does not show like the above image.
My Dialog open dialog code is bellow
lateinit var dialog: Dialog
dialog = Dialog(this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen)
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) // before
dialog.setContentView(R.layout.dialog)
dialog.setCancelable(true)
val lp = WindowManager.LayoutParams()
lp.copyFrom(dialog.getWindow()?.getAttributes())
lp.width = WindowManager.LayoutParams.MATCH_PARENT
lp.height = WindowManager.LayoutParams.MATCH_PARENT
dialog.getWindow()!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
val d: Drawable = ColorDrawable(Color.BLACK)
d.setAlpha(130)
dialog.getWindow()!!.setBackgroundDrawable(d)
dialog.show()
dialog.getWindow()!!.setAttributes(lp)
Here is my dialogx.ml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80000000"
android:orientation="vertical">
</LinearLayout>
Here is my color code
**fill color #000000 with alph 50%**
It shows the transparent background. How to make the dialog above image. Please help me.
Dialog dialog=new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);
dialog.setContentView(R.layout.dialog);
dialog.show();
I'm using Alert Dialog to show the custom view , but alert dialog comes very slowly. It approximately takes 10 or 15 seconds to show . Here my code what is wrong in that .
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View vDialog = layoutInflater.inflate(R.layout.dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(vDialog);
AlertDialog ad = builder.create();
ad.show();
Here my dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height ="match_parent" >
<CalendarView
android:layout_width="50dp"
android:layout_height ="50dp">
</CalendarView>
</FrameLayout>
Try This Code:
final Dialog dialog = new Dialog(context,
android.R.style.Theme_Translucent_NoTitleBar);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog);
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.CENTER;
dialog.getWindow().setAttributes(lp);
dialog.show();
// Try this way,hope this will help you to solve your problem.
dialog.xml
<CalendarView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height ="match_parent"/>
Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.dialog);
dialog.show();
I want to set the width of custom dialog to wrap content
but always it fill all the width of the screen
I have tested this
android.view.WindowManager.LayoutParams params = mydialog.getWindow().getAttributes();
params.width = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
mydialog.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
and that
mydialog.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
I also having a hard time in solving this problem and finally got a better way in solving this.
Here is the workaround. In your code
mydialog.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
This is not working because the default layout for ProgressDialog has match_parent with margins left and right. To resize the ProgressDialog you need a Custom View like below:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#android:drawable/dialog_holo_light_frame"
android:layout_gravity="center_horizontal"
android:id="#+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_marginLeft="30dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/progressBar"/>
<TextView
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_marginRight="30dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:gravity="center"
android:id="#+id/message"/>
</LinearLayout>
and inflate it after showing the ProgressDialog. After inflating the custom view, get the width of the custom view by using the GlobalLayoutListener and set the layout width.
mDialog.show();
final Window window = mDialog.getWindow();
window.setContentView(R.layout.custom_progress_dialog); // this is the above code
final LinearLayout dialogContainer = (LinearLayout) window.findViewById(R.id.container);
TextView message = (TextView) window.findViewById(R.id.message);
message.setText("Loading . . .");
dialogContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int width = dialogContainer.getWidth();
window.setLayout(width, WindowManager.LayoutParams.WRAP_CONTENT);
dialogContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
I know this question is old, but if someone doesn't want to add WindowManager.LayoutParams then just set theme of the dialog to android.R.style.Theme_Holo_Light_Dialog_NoActionBar this will make the dialog to wrap it's width to its contents.
Example:
AlertDialog alert = new AlertDialog.Builder(context, android.R.style.Theme_Holo_Light_Dialog_NoActionBar).create();
Make sure that the layout you are inflating is set to wrap_content for both height and width.
Did you try using this
mydialog.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
after writing mydialog.show()?
That should work.
Try below code to have a dialog with wrap content.
(In dialogs layout xml use layout_width= WRAP_PATENT and height as WRAP_CONTENT)
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
dialog.show();
dialog.getWindow().setAttributes(lp);
set style to custom dialog with following attribute:
<style name="CustomDialogTheme" parent="#android:style/Theme.Dialog">
<item name="android:windowIsFloating">false</item>
</style>
I am building a Custom dialog box using the Android Developer docs link , for this i made a layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rotatelayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#80000000"
>
<ImageView
android:id="#+id/dialogimage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
and i am inflating this dialog,
AlertDialog dialog;
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(TabsActivity.this);
LayoutInflater inflator = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflator.inflate(R.layout.rotate_dialog_layout, (ViewGroup) findViewById(R.id.rotatelayout));
ImageView image = (ImageView) view.findViewById(R.id.dialogimage);
image.setOnClickListener(new RotateLockListener());
image.setBackgroundColor(Color.parseColor("#80000000"));
if(locked)
{
image.setImageResource(R.drawable.lock_icon);
}
else
{
image.setImageResource(R.drawable.unlock_icon);
}
builder.setView(view).setCancelable(true);
dialog = builder.create();
dialog.setView(view, 0, 0, 0, 0);
timerDelayRemoveDialog(time, dialog);
dialog.show();
but still it appears as
I have tried all the help provided at the stack over flow
Setting ImageView background to transparent,
Setting transparency by #80000000 and
Setting Dialog window transparency
But none of them worked, it still showing up.
Or you can use Dialog class for this,
Dialog dialog = new Dialog(this,
android.R.style.Theme_Translucent_NoTitleBar);
Window window = dialog.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
window.setLayout(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.setContentView(R.layout.temp);
dialog.show();
Try using this as the style of your View :
<style name="Dialog_Fullscreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>
I have a simple request: I have to put some pictures (some small resolution, some big resolution) in a dialog and display them fullscreen.
I tried this:
Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.custom_dialog);
int picId = Integer.valueOf(webcamCursor.getString(webcamCursor
.getColumnIndex("_id")));
dialog.setTitle(webcamCursor.getString(webcamCursor
.getColumnIndex("City")));
image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.icon);
new DownloadPicTask().execute(Snippets.getUrlFromCat(picId, cat));
dialog.show();
And my layout is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
>
<ImageView android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
/>
</LinearLayout>
As I wrote fill_parent everywhere, shouldn't the dialog take the full screen?
Try that:
dialog.getWindow().getAttributes().width = LayoutParams.FILL_PARENT;
Hope it helps.
try this will work
//Grab the window of the dialog, and change the width
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = dialog.getWindow();
lp.copyFrom(window.getAttributes());
//This makes the dialog take up the full width
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(lp);