Change the Dialog style using a theme - java

I was wondering whether there is a simple way to tell Android to always use a custom style to display Dialogs.
Using themes and styles you can change the look and feel of all, say, TextViews using this piece of code when defining a theme in themes.xml:
<item name="android:textViewStyle">#style/Blue.TextView</item>
with Blue.TextView being defined in styles.xml.
Is there some way to do so for Dialogs as well ?

yes, there is. for example,
AlertDialog.Builder b = new AlertDialog.Builder(context, R.style.MyTheme);
or, if you are using a DialogFragment, just call the setStyle() method,

<style
name="Theme_Dialog_Translucent"
parent="android:Theme.Dialog">
<item
name="android:windowBackground">#null</item>
</style>
Below is the working code::
Dialog mDialog = new Dialog(this,R.style.ThemeDialogCustom);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setCanceledOnTouchOutside(true); //But here It is not workin
mDialog.setContentView(R.layout.popup);

Related

How to full screen activity with transparent status bar?

I would like to show transparent status bar without using immersive mode. Just like the image below. I have tried lot of solutions however I'm unable to achieve this. Please refer the image below.
This is the output I'm looking for. Please note here that I'm looking for solution which doesn't affect navigation bar at all. I don't want any modifications to navigation bar just like image below.
Thanks in advance!
My theme:
<style name="AppTheme" parent="#style/Theme.MaterialComponents.DayNight.NoActionBar.Bridge">
<item name="android:colorEdgeEffect">#color/color_subtitle_text</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>
try this:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
You can use like this.
For Kotlin:
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
For Java:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

Adding components programmatically has different style than those in XML layout

Components (text and edit boxes) defined in layout XML looks very different from those i add programatically.
I've tried to apply the same textAppearance style programatically as the ones from my XML has. I tried calling setTheme() after adding the components too. No difference.
TextView tv10 = new TextView(getApplicationContext());
tv10.setText("Back width");
EditText tv11 = new EditText(getApplicationContext());
tv11.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_CLASS_NUMBER);
TextView comes out with small font and gray text, EditText comes out with black background and gray text.
The components must be added programmatically because of options the user choose. Those user choices are defined in the XML and follow the expected color scheme, which is the Android Studio defaults. (Black text on white background)
You shouldn't use Application Context for views. Only Activity context. Also you can pass style as parameter, when create view in code.
As Yamko said, style can be passed in the constuctor
var textView = TextView(context, null, R.style.LoginBodyTextViewStyle)
where the style can be something like
<style name="LoginBodyTextViewStyle" parent="android:Widget.TextView">
<item name="android:textStyle">normal</item>
<item name="android:fontFamily">sans-serif</item>
<item name="android:textSize">#dimen/text_size_default</item>
<item name="android:textColor">#color/grey</item>
</style>

Android - how to disable / change editTexts 'Pin'

How can I edit or disable the 'pin' for editTexts that appears when marking text? I was able to edit the underline & the cursor, but not that 'pin' because I didn't know how to call it.
Image of the pin (pink) added.
I think the colourAccent influences the colour of that pin, try changing the colour of colourAccent in color.xml
This 'pin' is called "text select handle"
To change it you need to use these attributes:
text_select_handle_left and text_select_handle_right
Add these drawables with customized design/color to your drawable folder and add to style
<style name="MyTheme" parent="#style/MyCustomTheme">
<item name="android:textSelectHandle">#drawable/text_select_handle_middle</item>
<item name="android:textSelectHandleLeft">#drawable/text_select_handle_left</item>
<item name="android:textSelectHandleRight">#drawable/text_select_handle_right</item>
</style>

Welcome Activity with background of image

I use the theme to show my WelcomeActivity
#android:style/Theme.NoTitleBar.Fullscreen
But I found it will have a period of black background when the app start
So I want to change the background of this theme
then I use...
<style name="WelcomeTheme" parent="#android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#drawable/welcome_img</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
</style>
Although the background is changed , the Actionbar is also showing!!
the Actionbar doesn't show when I use Theme.NoTitleBar.Fullscreen
but it's showing when I use WelcomeTheme
how should I remove the ActionBar
Thanks for your help :)
-
By the way , in my WelcomeActivity extends Activity but not ActionBarActivity
Did you try one of those?
in Activity;
getActionBar().hide();
in Fragment;
getActivity().getActionBar().hide();
1. Make you welcome activity.
2. Go to styles xml file and create a style like that:
<!-- BWelcome application theme. -->
<style name="WelcomeTheme"
parent="android:Theme.DeviceDefault.NoActionBar.Fullscreen">
<!-- Customize your theme here. -->
</style>
3. Go to manifest file and add this to your welcome activity:
android:theme="#style/WelcomeTheme"
4. Add your welcome logo in an ImageView
5. Advice: Never use Java code if you can do it with XML
Hope it helps!
You can do this way:
WelcomeActivity extends ActionBarActivity:
on onCreate();
getSupportActionBar.hide();
In Layout file:
setBackground to Parent View:
Hope this will help you.

How to set dialog (Custom) a glittering effect?

In my android app, I've designed some layouts to set the custom dialog. But I face some problems while making border with glittering effect.
I've set the following style to my dialog:
<style name="MyDialog" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowTitleStyle">#style/DialogWindowTitle</item>
<item name="android:windowFrame">#color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">#drawable/alertbgc</item>
In the java snippet,I added the lines as follows:
final Dialog mydialog= new Dialog(this,R.style.MyDialog);
mydialog.setContentView(R.layout.mylayout);
But with this snippets I'm getting very dark background (I used nine patch images too, but no use). Please help me providing your ideas.
Thanks in advance

Categories