How to remove transparent dark background outside of dialog box - android

I want to remove a transparent dark backgrond outside of dialog box.
I tried with:
final Dialog dialog = new Dialog(this);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.WHITE));
this.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.WHITE));
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.spinner_layout);
getWindow().getDecorView().setBackgroundResource(android.R.color.transparent);

In addition to chuky's answer;
If your minSdkVersion value is greater than or equal to 14, you can use setDimAmount() method.
dialog.getWindow().setDimAmount(float amount);
According to reference;
amount The new dim amount, from 0 for no dim to 1 for full dim.
or
As stated previously, you can clear window flag.

Your question has already been answered here
Code from the link:
Add this to your styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.DoNotDim" parent="android:Theme">
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
And then apply the theme to your activity:
<activity android:name=".SampleActivity" android:theme="#style/Theme.DoNotDim">

Hope this will help you...
dialog.getWindow().getDecorView().setBackgroundResource(android.R.color.transparent);
dialog.getWindow().setDimAmount(0.0f);
dialog.show();

This didn't work for me
<item name="android:backgroundDimEnabled">false</item>
i used background dim amount instead of background dim enabled
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.DoNotDim" parent="android:Theme">
<item name="android:backgroundDimAmount">0</item>
</style>
</resources>

Using dialog.getWindow().setDimAmount(float amount); caused my statusbar icons to disappear.
Clearing the FLAG_DIM_BEHIND flag from window worked for me.
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

Related

Change listpreference Summary text color and size

I have listpreference in my app , i want to customize it , i can set theme to prefs activity as bellow :
<activity
android:name=".Prefs"
android:label="#string/app_name"
android:theme="#style/PreferencesTheme">
preference style:
<?xml version="1.0" encoding="utf-8" ?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="PreferencesTheme" parent="android:Theme">
<item name="android:background">#FFDAB9</item>
<item name="android:textColor">#color/red_color</item>
<item name="android:textSize">20sp</item>
</style>
</resources>
The above style changes the ListPreference background and ListPreference title text size and text color BUT it doesn't change ListPreference summary text color or size any way to do that ,
i tried this code but it doesn't work:
<item name="android:textColorSecondary">#color/red_color</item>
any help will be appreciated, thanks
Maybe it's too late to answer, but try to remove your line of color:
<item name="android:textColor">#color/red_color</item>
And add this which are for the primary, secondary and tertiary colors
<item name="android:textColorPrimary">#color/red_color</item>
<item name="android:textColorSecondary">#color/red_color</item>
<item name="android:textColorTertiary">#color/red_color</item>
You can choose the color you want to all those, honestly, I never saw the tertiary color in any preference page, but the primary is for the main and big text, the secondary is for the small text appears below the primary.
Hope it helps.
That sucks because the xml file says it uses textColorSecondary for the summary color.
What I would recommend you do is copy and save the contents of the file above into your own project, edit that file to look the way you want it to (Remember not to change any ids), and display a custom list preference item layout.
You can apply a custom preference layout in xml like so:
<ListPreference
android:key="pref_key"
android:title="#string/my_list_preference"
android:layout="#layout/custom_list_preference" />
I put this line into styles.xml and it works:
<item name="android:textColorSecondary">#00CC00</item>

Dialog in full Screen

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

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" />

Overriding the layout used for a preference in a preferenceActivity/preferenceScreen using theming

I have a preferenceActivity in my application and I have tried to set the preference style using the following theme:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyPreferenceTheme" parent="android:Theme.Translucent">
<item name="android:preferenceStyle">#style/MyPreference</item>
<item name="android:windowBackground">#color/transparent_black</item>
</style>
<style name="MyPreference" parent="#android:style/Preference">
<item name="android:layout">#layout/preference</item>
</style>
<color name="transparent_black">#BB000000</color>
So I know that the theme is loading as the background is colored correctly. However my custom preferenceLayout (res/layout/preference.xml) is not getting applied to any of the preferences inside my preferenceActivity.
Is this the correct way to achieve theming of the preferences? or have I missed something?
Thanks in advance :)
I found that it's best not to use parent="android:style/Preference" as it doesn't seem to apply the style I'm trying to override it with. Style your layout that you're using (#layout/preference) and drop the inheritance from the android:style/Preference. It worked for me when I had to do the same.
so it should be:
<style name="MyPreference">
<item name="android:layout">#layout/preference</item>
</style>
Good luck!
That's a bug. See this issue.
You can "fix" it by assigning an ID for every PreferenceScreen. Then, you do this for every :
((PreferenceScreen) preferenceScreen).getDialog().getWindow().setBackgroundDrawable(drawable);
Good luck
Tom

Android Borderless Dialog

I have created an AlertDialog using AlertDialog.Builder, but the Dialog border takes up too much space on the screen. How do I remove the border? I have tried using another Activity to emulate the dialog with a transparent background, but the dialog is used repeatedly, and creating a new Activity every time introduces a significant amount of lag.
The answer from here mentions that it can be found in the ApiDemos, but i can't seem to find it.
Alright, I'll answer my own question. Basically, instead of using AlertDialog.Builder, create a regular Dialog using it's constructor, and use a suitable theme instead of the default Dialog theme.
So your code would look something like this:
Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
Hope this helps someone else.
Here is my solution, to get a dialog that shows only your content.
Dialog dialog = new Dialog(this,R.style.ThemeDialogCustom);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
//you can move the dialog, so that is not centered
// dialog.getWindow().getAttributes().y = 50; //50 should be based on density
dialog.setContentView(yourLinearLayout);
dialog.setCancelable(true);
//dialog.setOnCancelListener(cancelListener);
dialog.show();
themes.xml // located in project /res/values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ThemeDialogCustom">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowBackground">#color/transparent_color</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:colorBackgroundCacheHint">#null</item>
</style>
</resources>
colors.xml // also located there
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent_color">#00000000</color>
</resource>
Using android.R.style.Theme_Translucent_NoTitleBar works if you want the dialog to be full screen. An alternative is to create your own style, like so:
<style
name="Theme_Dialog_Translucent"
parent="android:Theme.Dialog">
<item
name="android:windowBackground">#null</item>
</style>
try this :D
Dialog popUpView= new Dialog(this);
popUpView.getWindow().setBackgroundDrawable(new ColorDrawable(0));
I added a transparent pixel to drawable and used the following code :
dialog.getWindow().setBackgroundDrawableResource(R.drawable.transpix);
if you have 2 border you need to use a ContextThemeWrapper, which it will show only one border as you would like :)
ContextThemeWrapper wrapper = new ContextThemeWrapper(this, android.R.style.Theme_Holo);
final LayoutInflater inflater = (LayoutInflater) wrapper.getSystemService(LAYOUT_INFLATER_SERVICE);
AlertDialog.Builder builder = new AlertDialog.Builder(wrapper);
You can ask the builder to enforce inverse background. Worked for me to display a borderless splash screen with a png source.
In your resources file create a xml file named for e.g. null_image.xml, with the following content:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#0000" />
<size
android:height="1dp"
android:width="1dp" />
</shape>
In your java code, fetch the dialog window and set the xml file as the drawable resource, like this:
Depending on your context:
Dialog dialog = new Dialog(getContext());
Window window = dialog.getWindow();
window.setBackgroundDrawableResource(R.drawable.null_image);
That's it, enjoy.

Categories

Resources