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.
Related
I am building a dialog with DialogFragment, and I need to change the color of the shadow (mask), which is transparent and always around the main dialog content. Actually, almost all of the answers on the web is to change the dialog box color, but I need to change the shadow color from transparent black to others. Is there any way to do that?
image:
If you only want to change the alpha for the background then you can easily create a style with android:backgroundDimAmount attribute, like I did
<style name="CustomAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="android:backgroundDimAmount">0.5</item>
</style>
the value ranges 0-1 and then passing the style in your AlertDialog as
AlertDialog dialog = new AlertDialog.Builder(this, R.style.CustomAlertDialogStyle)
.setTitle("Title").setMessage("message").create();
dialog.show();
But if you want to change the background color as well then you can try this work around given by #Lee Han Kyeol
https://stackoverflow.com/a/29482234/5002610
I hope this will solve your issue.
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 :)
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);
I have created custom style for checkbox
<style name="CheckBoxtpi" parent="android:Widget.CompoundButton.CheckBox">
<item name="android:button">#drawable/tpi_btn_check_holo_light</item>
</style>
And apply it to my Theme, it works pretty, but all checkboxes in alert dialogs still standart Holo Blue color.
How can i change this?
There are two alternatives you can do;
Change your context from getApplicationContext() or any other to explicitly MyActivity.this, (whatever your activity name is) when you build your dialog.
This will probably solve the problem.
You may create a custom layout for the dialog box and call it
dialog.setContentView(R.layout.custom_dialog);
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