Dialog in full Screen - android

My question is i don't want to show transparent dialog in full screen
below is the code i used
dialog = new Dialog(this, R.style.CustomDialogTheme);
dialog.setContentView(R.layout.enterjoinseecode_dialog);
CustomDialog theme
<style name="CustomDialogTheme" parent="#android:style/Theme.Translucent.NoTitleBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowFullscreen">false</item>
</style>
Please some one helps me where i went wrong

Try this.Create your view for Dialog like below.
<RelativeLayout
android:layout_width="450dp"
android:layout_height="250dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
// Here you can add your component.
</RelativeLayout>
And set your dialog this view.
dialog = new Dialog(this, R.style.CustomDialogTheme);
dialog.setContentView(R.layout.enterjoinseecode_dialog);
That's it.Hope this will help you.

Create a activity with transparent background and for that particular activity define theme like this
<activity android:theme="#android:style/Theme.Dialog" />
And also if you want that activity to be exactly like dialog, then you can also use this
android:excludeFromRecents="true"
to remove it from the recent apps list.

some how with the following steps got the dialog with transparent effect with out full screen
No need of defining style "CustomDialogTheme" need to pass the theme argument for constructor as android.R.style.Theme_Translucent_NoTitleBar
and with in inflated xml just used background as android:background="#29000000" to make it transparent effect and layout_gravity property to position the dialog
if i use the above style CustomDialogTheme somehow its showing as a window instead of dialog because of that i applied direct theme to show that as dialog (not full screen)and to make it transparent effect with in xml i set the property background

Related

Not able to set transparent background for Popup Window Activity

I am following this particular example to create a popup window activity but when I click on a button to open this activity, the background is not semi-transparent as mentioned in the example. I am new to android kotlin development so I am not able to figure this out on my own. Let me know what I am doing wrong.
EDIT: This link tells a different method but working fine.
You can customize the translucent theme of your activity, in your "AndroidManifest.xml" file.
<activity
android:name=".ui.PopUpWindow"
android:theme="#style/AppTheme_translucent" />
and in your "styles.xml" file.
<style name="AppTheme_translucent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowBackground">#color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
</style>
I travel the code and did not see setContentView() method for PopupWindow activity. Please set content view for the activity by calling the method inside PopupWindow's onCreate()

What is the best way to create smaller size layout for an activity

I have a requirement that when user clicks on "View Card" button, open a smaller size activity that is not covering the complete screen.
I did and some R&D and find out multiple options for achieving this.
1- Create a layout file, and create a custom Dialog in your activity like following.
//OnClickListener
Dialog dialog = new Dialog(main.this);
dialog.setContentView(R.layout.maindialog);
dialog.setTitle("This is my custom dialog box");
dialog.setCancelable(true);
//this can have buttons and other stuff
2- Create a Dialog Fragment
3- Create a new activity, and add following line in the Manifest
android:theme="#android:style/Theme.Translucent"
I am unable to understand which one is better approach to achieve this.
You could create a custom theme for you activity in styles, with a custom navigation icon for example:
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="navigationIcon">#drawable/ic_clear_white_24dp</item>
</style>
Then, you can add this theme to your activity, in Manifest:
<activity
android:name=".YourActivityName"
android:theme="#style/DialogTheme" />
In this moment, you have a activity with a custom theme based in Dialog. If you want to put width and height custom values to your root layout, you can do it:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="300dp"/>
<!-- Your activity content... -->
</FrameLayout>
Actually, it's depend on you whether use activity,dialog.
for eg :
If data is short and just need to show/write some small info then use dialog.
Even you could try hidden (view/layout) and on click show that hidden (view/layout) with some animation ,after work hide.
even you can use now bottomsheet too :)

Change background color when a Popup is shown

I want to make the background darker when a PopupWindow is shown. Just like Dolphin Browser does like-
Before the PopupWindow
After the PopupWindow
The background color is darker than what it was. So, how can we do this?
In your xml file add something like this with width and height as 'match_parent'.
<RelativeLayout
android:id="#+id/bac_dim_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C0000000"
android:visibility="gone" >
</RelativeLayout>
In your activity oncreate
//setting background dim when showing popup
back_dim_layout = (RelativeLayout) findViewById(R.id.bac_dim_layout);
Finally make visible when you show your popupwindow and make its visible gone when you exit popupwindow.
back_dim_layout.setVisibility(View.Visible);
back_dim_layout.setVisibility(View.GONE);
If i am not wrong... you can create an activity with listview.... and put the theme as dialog in its manifest like this..
<activity android:theme="#android:style/Theme.Dialog" />
this will make the background darker..
try this code if your popup is an activity then it will help definetly.
make a mystyle.xml file in values folder of your project and make these changes.
<resources>
<style name="customStyle" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
</style>
</resources>
do this change in
menifest.xml
<activity android:name="yourActivity" android:theme="#style/customStyle"></activity>
fun setBackgroundAlpha(activity: Activity, bgAlpha: Float) {
val lp: WindowManager.LayoutParams = activity.getWindow().getAttributes()
lp.alpha = bgAlpha
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
activity.getWindow().setAttributes(lp)
}

How to create a fully customized Alert Dialog?

Is there a solution to create an Alert Dialog with no borders around? If I create a layout and attach it to the Alert Dialog, I have my layout shown, but it's surrounded by the default dialog borders. Any way to cut them off? Thanks in advance.
Here is one way (if you don't like this particular example with the green border, scroll below to see a second one I found).
Here is another example (this one gives you an example without a border, and one with a border. The explanations are in Japanese, but the code is given for both.)
Hi if you use your own layout then set this in your styles.xml
<style name="Theme.Transparent_layout" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
and set this style in your manifest file
<activity android:name=".Main" android:theme="#style/Theme.Transparent_layout" />

How can I get a Dialog style activity window to fill the screen?

I am using an activity with the dialog theme set, and I want it to be full screen. I tried all sorts of things, even going through the WindowManager to expand the window to full width and height manually, but nothing works.
Apparently, a dialog window (or an activity with the dialog theme) will only expand according to its contents, but even that doesn't always work. For instance, I show a progress bar circle which has width and height set to FILL_PARENT (so does its layout container), but still, the dialog wraps around the much smaller progress bar instead of filling the screen.
There must be a way of displaying something small inside a dialog window but have it expand to full screen size without its content resizing as well?
I found the solution:
In your activity which has the Theme.Dialog style set, do this:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
It's important that you call Window.setLayout() after you call setContentView(), otherwise it won't work.
You may add this values to your style android:windowMinWidthMajor and android:windowMinWidthMinor
<style name="Theme_Dialog" parent="android:Theme.Holo.Dialog">
...
<item name="android:windowMinWidthMajor">97%</item>
<item name="android:windowMinWidthMinor">97%</item>
</style>
I just want to fill only 80% of the screen for that I did like this below
DisplayMetrics metrics = getResources().getDisplayMetrics();
int screenWidth = (int) (metrics.widthPixels * 0.80);
setContentView(R.layout.mylayout);
getWindow().setLayout(screenWidth, LayoutParams.WRAP_CONTENT); //set below the setContentview
it works only when I put the getwindow().setLayout... line below the setContentView(..)
thanks #Matthias
Wrap your dialog_custom_layout.xml into RelativeLayout instead of any other layout.That worked for me.
For Dialog
This may helpful for someone.
I want a dialog to take full width of screen. searched a lot but nothing found useful. Finally this worked for me:
mDialog.setContentView(R.layout.my_custom_dialog);
mDialog.getWindow().setBackgroundDrawable(null);
after adding this, my dialog appears in full width of screen.
This answer is a workaround for those who use "Theme.AppCompat.Dialog" or any other "Theme.AppCompat.Dialog" descendants like "Theme.AppCompat.Light.Dialog", "Theme.AppCompat.DayNight.Dialog", etc.
I myself has to use AppCompat dialog because i use AppCompatActivity as extends for all my activities. There will be a problem that make the dialog has padding on every sides(top, right, bottom and left) if we use the accepted answer.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
On your Activity's style, add these code
<style name="DialogActivityTheme" parent="Theme.AppCompat.Dialog">
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">#null</item>
</style>
As you may notice, the problem that generate padding to our dialog is "android:windowBackground", so here i make the window background to null.
Set a minimum width at the top most layout.
android:minWidth="300dp"
For example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="300dp">
<!-- Put remaining contents here -->
</LinearLayout>
Matthias' answer is mostly right but it's still not filling the entire screen as it has a small padding on each side (pointed out by #Holmes). In addition to his code, we could fix this by extending Theme.Dialog style and add some attributes like this.
<style name="MyDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
</style>
Then we simply declare Activity with theme set to MyDialog:
<activity
android:name=".FooActivity"
android:theme="#style/MyDialog" />
This would be helpful for someone like me. Create custom dialog style:
<style name="MyDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">false</item>
</style>
In AndroidManifest.xml file set theme for wanted activity:
<activity
android:name=".CustomDialog"
...
android:theme="#style/MyDialog"/>
That is all, no need to call methods programaticaly.
In your manifest file where our activity is defined
<activity
android:name=".YourPopUpActivity"
android:theme="#android:style/Theme.Holo.Dialog" >
</activity>
without action bar
<activity android:name=".YourPopUpActivity"
android:theme="#android:style/Theme.Holo.Dialog.NoActionBar"/>

Categories

Resources