Android - FEATURE_NO_TITLE not working - android

I am trying to display my about us page via layout, so I don't need any title bar. I tried:
Dialog d = new Dialog(this);
d.setContentView(R.layout.about_us);
d.setCanceledOnTouchOutside(true);
d.requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
d.show();
but when I click on the menu item, it force closes. when I comment the third line of the code above, it shows my layout with title bar, which I don't need.
P.S.: my activity extends ActionBarActivity, is this the reason? If yes then I need an alternative.

Pass a theme to your dialog can remove the title bar for you.
Add the following code in your res/values/styles.xml:
<style name="NoTitleDialog" parent="#android:Theme.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
Pass the theme to your dialog:
Dialog d = new Dialog(this, R.style.NoTitleDialog);

Related

If I set theme of activity so the popup of that activity should not change ,Is this possible?

While launching my app the blank screen is appear, for resolving this theme has been set to android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
But alert dialog of this activity also get change.
I don't want to change the theme of dialogues.
How can I do that?
If you want to use a default theme create the dialog like this:
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_Dialog));
If you want to make further changes to the Dialog create a custom style in your xml
<style name="CustomDialog" parent="#style/Theme.AppCompat.Dialog">
// insert your custom attributes
</style>
Then the creation of the dialog would be:
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this,R.style.CustomDialog));
You can use the style in DialogFragments as well using setStyle(STYLE_NORMAL, R.style.CustomDialog); inside onCreate

Styling custom dialog fragment not working

I'm trying to style all my dialog fragments to look the same in my app. The dialogs coming from my settings fragment are styled exactly the way I want it. For my custom dialog fragments, the style is similar but not exactly the same. For some reason the spinner, timepicker, datepicker, radiobuttons, and edittext widgets inside my custom dialog fragments don't pick up the same style. In fact, the widgets blend in with the white background and you can't see that they are there. What am I doing wrong?
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"/>
<style name="Theme.Base" parent="AppTheme">
<item name="colorPrimary">#color/PrimaryBackgroundColor</item>
<item name="colorPrimaryDark">#color/SecondaryBackgroundColor</item>
<item name="colorAccent">#color/ColorBackgroundAccent</item>
<item name="android:textColorPrimary">#color/PrimaryTextColor</item>
<item name="android:alertDialogTheme">#style/AppTheme.DialogStyle</item>
</style>
<style name="AppTheme.DialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">#color/PrimaryBackgroundColor</item>
<item name="colorAccent">#color/ColorBackgroundAccent</item>
</style>
I'm applying the theme to my custom dialog fragment like this:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppTheme_DialogStyle);
My settings dialog looks like this (Exactly how I want it):
Settings Dialog Fragment
My custom dialog fragment looks like this:
Custom Dialog Fragment
As you can see, the radio button selected color red and you can't see the unselected radio button.
Finally got an answer!!!
It's an issue or bug with AppCompat 22+.
Check out link here
Apparently this was a bug with fragments and widgets weren't getting the material themed in a fragment. It seems they fixed this issue, but the issue still holds in a dialog fragment based on what I'm going through.
The problem comes when you use the inflater instance passed to Fragment#onCreateView(). The workaround for now is to instead used the LayoutInflater from getActivity().getLayoutInflater() according to google.
So I changed my code to:
View view = getActivity().getLayoutInflater().inflate(R.layout.dialog, null);
from:
View view = LayoutInflater.from(getActivity().getApplicationContext()).inflate(R.layout.dialoge, null);
All my widgets are now themed. Thanks everyone. Hopes this helps someone else.
I believe you need to set the theme on the actual Dialog and not the Fragment
Use this constructor to create your AlertDialog:
AlertDialog.Builder(Context context, int theme)
ie
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), theme)
I think you need to add one more item in style of your dialog. android:textColorSecondary will show color of un selected checkbox.
in your style add it.
</style>
<style name="AppTheme.DialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">#color/PrimaryBackgroundColor</item>
<item name="colorAccent">#color/ColorBackgroundAccent</item>
<item name="android:textColorSecondary">#000000</item>
</style>
It will make un Checked checkbox or toggle button edge color black. you need to change #000000 to color your want to show.
See if this helps -
Android appcompat-v7:21.0.0 change material checkbox colors
In short, try setting android:textColorSecondary.

Changing Background dim color for dialog appears in android

Hi I have to chage the dim color of dialog in my theme to white, so that by setting layoutParams.dimAmount = 0.5f; i can get blur white in dialog background.
I am using
<style name="MyDialog" parent="#android:style/Theme.Holo.Light.Dialog">
<item name="android:windowBackground">#color/dialog_dim_background</item>
</style>
and following below references
How do I create a transparent Activity on Android?
Custom screen dim with Dialog
It is a very old question, but i'd like to add n answer to it. I faced the same problem and googled a lot. Then came up with my own solution.
First of all, I removed the dim at all with this
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
And then I opened my layout(it was RelativeLayout) and put this view in it as the last element
<View
android:id="#+id/shade"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/primaryShadow"
android:visibility="invisible"/>
The background color is the color you want to use as your dim color. As you can see, it is invisible when created. So you'll need to find it in you Activity and set it's visibility before you launch the dialog to View.VISIBLE. When you cancel dialog, set it to View.INVISIBLE again. And that's it.
I know it's very old question but this will help out surely to someone who is using AppCompatActivity or ActionBarActivity. If you are setting a dialog to your activity or say DialogActivity then also the below will work!
dialog = new Dialog(ActivityName.this);
dialog .setCancelable(false);
dialog .setContentView(R.layout.dialog_layout);
Window window = dialog.getWindow();
if(window != null){
window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setDimAmount(0.5f);
//If you are setting a dialog activity
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
Double dialogWidth = displayMetrics.widthPixels * 0.50;
window.setLayout(dialogWidth.intValue(),
WindowManager.LayoutParams.WRAP_CONTENT); //Setting it cover half of the screen width
}
dialog.show();
Just before you dismiss the dialog,
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.dismiss();
//If you are setting a dialog activity, create a style in styles.xml:
<style name="MyTheme" parent="#style/Theme.AppCompat.Light.Dialog">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
And in your Manifest, set the theme:
<activity android:name=".view.POSSelectCustomerDialogActivity"
android:theme="#style/MyTheme"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"/>
Ok here is how I do that "I don't know how will these behave with the blur flag though"
I create a custom layout for the dialog with a background color of my choosing .
set the dialog to fill screen
remove the dim behind flag
Code snippet
Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dailog_layout);
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(0));
dialog.getWindow().setLayout(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
dialog.getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Best of luck

Create a transparent dialog on top of activity

Background
I'm trying to put a layer on top of the current activity which would have explanation of what is going on on the current screen, similar to what occurs on contact+ app .
I know there are some solutions for this (like the showCase library and the superToolTips library ) , and I also know that I can create a view and set it on top by adding it to the window of the activity , but I need put a whole dialog layer on top.
Problem
No matter what I try, each solution doesn't work the way I need it to work.
in short , what I need is:
full screen dialog.
no change (not visual and not logical) to the action bar, notification bar, and content of the activity behind, meaning that everything behind the dialog stays the same it was shown a moment before the dialog was shown.
be transparent except for the views I use for the dialog, which should be shown normally.
what I've tried
Sadly, I've always got only a part of the things I needed.
here's my code:
styles.xml:
<style name="full_screen_dialog">
<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:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
MainActivity.java:
...
final Dialog dialog = new Dialog(this, R.style.full_screen_dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.floating_tutorial);
dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
dialog.getWindow().setFormat(PixelFormat.TRANSLUCENT);
dialog.show();
This code will put the layout on top of the activity, but sadly it doesn't have any transparency , even though I've set it . The layout I've used is very simple which is why I don't post it.
Question
what am I missing ? what should be done to fix the code?
how can I make the dialog both transparent, full screen AND that it won't change the action bar and notifications bar.
Working solution
EDIT: after finding a good solution, here's the working code:
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.floating_tutorial);
final Window window = dialog.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
Just change the background color of your Dialog:
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Edit:
This prevents the dim effect:
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Just add this, it really works!
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowCloseOnTouchOutside">true</item>
<item name="android:windowBackground">#android:drawable/alert_dark_frame</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>

change progressdialog background

In my android application I am using progress dialog in my splashscreen.
I would like to see only the progressbar with loading message without the background.
Is there any way that I can change the background to transparent in Android?
Please share your valuable suggestions.
ProgressBar should be placed on the Layout and then you have to set or change the progressbar in your activity.
Beware of setting the background before setting max, min, progress and text or it will not render correctly.
you can get it by defining the progressbar and the text in your xml file and you control it in your activity.
As MGS says, you can put the <Progressbar> in your layout xml file itself. Moreover you want to customize your ProgressDialog then you have to study the CustomDialog Tutorial in the Documentation. It explains everything about Dialog completely.
You can do this with the help of custom dialog instead of using progress dialog.
Custom dialog will be a better approach to do this .
Follow the link.
You can also use
android:background="#android:color/transparent"
in the background property of the parent layout in order to make it transparent.
Hope this will solve your problem
make layout .xml file which you want to display in Dialog then Create Object of Dialog
Dialog dialog = new Dialog(main.this);
dialog.setContentView(R.layout."your_layout");
dialog.setTitle("This is my custom dialog box");
dialog.setCancelable(true);
Create a dialog set set the dialog style to following:
<style name="CustomDialogTheme" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowNoTitle">true</item>
</style>
For ex:
Dialog dialog = new Dialog(main.this,R.style.CustomDialogTheme);
dialog.setContentView(<layout>);
Just put your progress bar in layout.

Categories

Resources