Android: a pop-up dialog style window - android

Right now I have a popupWindow being dynamically populated with a check-list.
This window pops up when the user taps the check-list button on screen.
However, the items in the background are not being faded out and they seem are still click-able.
I've tried Dialog.Builder but those windows are instantly dismissed when the user taps outside the range of the check-list.
so right now I have
PopupWindow newPop = new PopupWindow(ActionBar.LayoutParams.MATCH_PARENT,ActionBar.LayoutParams.WRAP_CONTENT);
That is generating the popup.
Then there is my root element for the popup.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/shadow"
android:layout_gravity="center"
android:gravity="center"
android:id="#+id/TopChecklist"> generating check-list here </LinearLayout>
So, can anyone recommend a way for the background to be un-touchable and to be faded?
EDIT:
Nevermind, I found a trick to get around it.
I changed the layout_width to fill_parent under the XML
Then I changed
android:background="#drawable/shadow"
To a rectangle object with color value #88000000
Now the buttons in the background can't be tapped and it all looks faded
Floor is still open for anyone that has a better way of doing it.

An AlertDialog should do the trick. Refer to: http://www.mkyong.com/android/android-custom-dialog-example/

I don't know if I understand your question right,
but you could use a normal Dialog like this:
public void ShowMyDialog() {
Dialog myDialog = new Dialog(context);
myDialog.setContentView(R.layout.MyLayout);
and use:
myDialog.setCanceledOnTouchOutside(false); //Dialog not cancelable when clicked outside dialog
or
myDialog.setCancelable(false); //Dialog not cancelable with back key
and dynamically at your checklist...

Related

Android setting the visibility of main activity

Is it possible to set the visibility of the MainActivity page in android to invisible or make it transparent may be? I have tried setting the visibility to invisible and also made height width as 0dp but this still shows the mainactivity with a white background and blue header.
What I am trying to achieve is, I am opening a floating window which is draggable on click of a button in the mainactivity, but I want to directly open the floating window by triggering the button click from the code itself. This works but the mainactivity still shows up for a second before the floating window is opened. I want to make the mainactivity page invisible or transparent so the mainactivity page is not noticeable.
Here is the XML of mainactivity.xml ,
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="Invisible"
android:background="#color/material_on_primary_disabled"
tools:context="com.example.widget_android.MainActivity">
<Button
android:id="#+id/open_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="Open Widget" />
on click of open_widget(which is triggered from code rather than the user having to click on it) the floating window is opened up.
I want to take the user directly to the floating window rather than the landing page which is the mainactivity page.
Here is what is happening on the backend java code
findViewById(R.id.open_widget).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startService(new Intent(MainActivity.this,WidgetService.class));
finish();
}
});
findViewById(R.id.open_widget).performClick();
The reason you get a white screen is because that is the default behaviour. You've tried to put an invisible, transparent, or non-existing (size of 0 pixels) View on top of the default View, so you are still seeing the default View. What you need to do is to replace the default View with a transparent View.
See How do I create a transparent Activity on Android? for information on how to get a transparent Activity.

My Android AlertDialog is not moving up out of the way when the keyboard is shown

So I have a alert dialogue which I call from an activity when a button is pressed:
Button editLocation = (Button) itemView.findViewById(R.id.edit_trained_location_button);
editLocation.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showEditLocationDialog();
}
});
public void showEditLocationDialog(){
LayoutInflater inflater = activity.getLayoutInflater();
AlertDialog.Builder builder =
new AlertDialog.Builder(activity, R.style.AppTheme);
builder.setTitle("Edit Location name");
builder.setPositiveButton("Save", null);
builder.setNegativeButton("Cancel", null);
builder.setView(inflater.inflate(R.layout.location_dialog, null));
Window newLocationDialog = builder.show().getWindow();
newLocationDialog.setLayout(DpToPxHelper.convertToPx(350, activity),
DpToPxHelper.convertToPx(175, activity));
newLocationDialog.setDimAmount(.8f);
newLocationDialog.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
}
Here is a the layout file.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:isScrollContainer="false"
android:id="#+id/location_name_edit_text"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"/>
</LinearLayout>
(The buttons are defined in the builder, the layout only allows me to create an EditText field).
So my problem is when I bring up the keyboard to enter text into the EditText field the dialogue isn't pushed up so the buttons at the bottom are blocked:
Before keyboard
After Keyboard
So what's weird is the text inside of the dialogue is pushed up...but the window isn't :(.
What I've tried:
<android:windowSoftInputMode="adjustPan">
I've added that to the manifest.xml and observed that it still doesn't move the dialogue box up.
<activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity>
I've tried this as well but it still has no affect.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
I've also tried that with no luck, the same behaviour happens the dialogue doesn't move up but the text inside gets pushed up.
Not trying anything (so no declaring in the manifest or .setSoftInputMode(...) ) I see the same behaviour so I don't think steps 1,2,3 have had any affect anyway.
So I've tried everything I could find on this site and I'm struggling to find a solution. I feel the issue is related to the layout some how.
If anyone can help me find a solution that would be great.
Thanks
I fixed it :D.
So the only problem was I was using the constructor builder(Activity..., Theme...).
Using the constructor builder(Activity...) (without theme) worked! I guess because it picks up the theme settings from that activity.

Android dialog without title not centered horizontally

I always create custom dialog without title to make it centered (both vertical and horizontal) using android:windowNoTitle in styles.xml or requestWindowFeature(Window.FEATURE_NO_TITLE) but some of my dialogs are not center horizontal, for example this dialog:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="20dp"
android:gravity="center"
android:background="#drawable/dialog_bg" >
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="#layout/loading_s"/>
<TextView
android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:gravity="center_vertical"
android:text="#string/loading"
android:textColor="#color/dialog_text"
android:textSize="#dimen/dialog_title_text_size" />
</LinearLayout>
This is how to create dialog:
#Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
View v = LayoutInflater.from(getActivity()).inflate(R.layout.dlg_progress, null);
Dialog dlg = new Dialog(getActivity(), R.style.My_Dialog_Style); //My_Dialog_Style contains android:windowNoTitle = true
dlg.setContentView(v);
dlg.setCanceledOnTouchOutside(false);
dlg.setCancelable(true);
return dlg;
}
And here is how it appears on screen
If I remove android:windowNoTitle attribute this dialog show correctly so the problem only occurs when using dialog without title.
Does anyone know why this happen and how to make dialog always center on screen?
have you tried looking at this thread?
How to align custom dialog centre in android ?
android:layout_gravity="center"
It looks like its just a layout change, or try using relativeLayout or LinearLayout instead of FrameLayout
When you use Builder and set a custom view with setView, it should not be necessary to remove the Dialog's title and the dialog should be centered.
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.dlg_progress, null));
return builder.create();
}
This is very similar to how it is done in the docs: Creating a Custom Layout
I believe you're running lower the dialog's minimum width attribute. It can be found as
<item type="dimen" name="dialog_min_width_major">65%</item>
in Android's framework. It varies depending on which values folder you're looking at, so it differs depending on density, orientation, etc.
You may be able to overwrite this value in your style. If you set it to something that is definitely smaller than your dialog(10%), it may work properly. If not, read on.
If you notice in your view tree panel, it shows your LinearLayout nested inside 3 FrameLayouts. My guess is that the deepest FrameLayout has its width set to wrap_content, so it's not filling the parent layout and is only as big as your LinearLayout. I can't be sure, though, because the dimensions are chopped off in your picture.
Why it changes when you remove the title? I don't know. You can hack it by adjusting the padding/layout params in onMeasure, but it seems like there should be a cleaner way to do it.
Still don't know why removing title make Dialog not centered horizontally but when I set min_width attr of LinearLayout = dialog minWidth this problem gone away.

Dim background like when displaying a dialog

I would like to obtain the same effect as when a modal dialog is displayed, i.e. dimmed background, can't interact with it, but to have a layout element, or more, active "on top" of the rest. For example: I tap on an icon and a panel with detailed information appears from the left, and you can do some stuff on that panel, the rest of the screen is dimmed, inactive. How can I do this? Thanks.
You can start a new Activity with the background set to transparent on some elements, for example:
<ScrollView
android:gravity="left"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent">
There is also an example of a TranslucentActivity in the Android API Demos:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/TranslucentActivity.html

Understanding android dialog layouts

I'm making a simple custom dialog for my android app, displaying only a seek bar. However, the complications of this simple task are driving me nuts.
My layout for the dialog is as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<SeekBar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/dialogVolumeSlider"
android:layout_width="225dp"
android:layout_height="wrap_content"/>
</LinearLayout>
The dialog is created in code:
Dialog d = new Dialog(this);
d.setContentView(R.layout.custom_dialog);
return d;
Instead of a simple box wrapping the seekbar, I get this phantom space coming from somewhere:
What's the issue here? I've tried modifying
d.getWindow().getAttributes().height
but this creates additional problems as well.
Thanks for any help!!
EDIT: Stranger things happen when I assigned a fixed "50dp" to my LinearLayout's layout_height:
By default a Dialog will leave space for a title even if you don't set one (with d.setTitle()) .
You can either set a title to fill the space or request that the Dialog not have a title.
Here is an example of how to request the no title setting.
Dialog d = new Dialog(this);
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
d.setContentView(R.layout.custom_dialog);
With no title, your SeekBar will appear as you expect.
Try putting a fixed Height on your parent linear layout. Something like:
android:layout_height="50px"

Categories

Resources