I am currently trying tu build my own DialogFragment theme.
One of my requirement is to use an icon at the right of the title.
First idea
Simply using:
this.getDialog().getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.dialog_title);
But unfortunately, this line of code has no result.
Second idea
Provinding my own layout -this.setContentView()- with this textview:
<TextView
android:id="#+id/tvTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="From XML"
android:textAppearance="#android:style/TextAppearance.DialogWindowTitle" />
This works, because I can read the text, but it still written in default black font.
I was expecting TextAppearance.DialogWindowTitle to give my text a title appareance (blue in Holo with big font size)
Any idea or suggestion?
EDIT
This nearly did the trick:
<style name="Dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/MyOwnDialogTitle</item>
</style>
<style name="MyOwnDialogTitle">
<item name="android:drawableRight">#drawable/MyRightImage</item>
</style>
but android:drawableRight just broke the title layout:
SECOND EDIT
This is a little bit better:
<style name="Dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/MyOwnDialogTitle</item>
</style>
<style name="MyOwnDialogTitle">
<item name="android:textAppearance">#android:style/TextAppearance.DialogWindowTitle</item>
<item name="android:drawableRight">#drawable/icon</item>
</style>
Maybe you can extend the default style in this manner:
res/values/dialogstyles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/MyOwnDialogTitle</item>
</style>
<style name="MyOwnDialogTitle">
<item name="android:drawableRight">#drawable/MyRightImage</item>
</style>
</resources>
res/values-v11/dialogstyles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Dialog" parent="#android:style/Theme.Holo.Dialog">
<item name="android:windowTitleStyle">#style/MyOwnDialogTitle</item>
</style>
</resources>
And override your DialogFragment's onCreate:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.Dialog);
}
Working Example
I am searching for your first requirement. but for second requirement, why dont you try with changing the color to style of the TextAppearance.DialogWindowTitle with your custom style ?
I have just check the android resources where there is style like below:
<style name="DialogWindowTitle">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAppearance">#style/TextAppearance.DialogWindowTitle</item>
</style>
and for TextAppearance.DialogWindowTitle style:
<style name="TextAppearance.DialogWindowTitle">
<item name="android:textSize">18sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">?textColorPrimary</item>
</style>
Now, you can change the color of your TextAppearance.DialogWindowTitle style and do as you want.
Hope you got the point.
Feel free to comment.
Have you tried to use #android:style/Theme.Holo.Light.Dialog as your parent in styles? This will work only in Android 3+ because in earlier version there is no theme Holo, but you can create your own to look like it for lower versions of Android.
Related
Android,How to do styling in textView . I want to style the text of textView, i am trying style for textView (text) border means suppose i have written "HELLO" in white color and font is bold so,now i want to make a border (style) on "HELLO" with red color but i don't understand how to do that ? I tried a lot but it won't work as i want it and there are so many errors in my code ...Please help me ..!
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:capitalize">characters</item>
<item name="android:textSize">12pt</item>
<item name="android:textColor">#ffffff</item>/>
<item name="android:textborderColor">#ff00ff</item>
</style>
</resources>
you can use style like this , In style xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="newtextview" parent="Widget.AppCompat.Textview">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:capitalize">characters</item>
<item name="android:textSize">12pt</item>
<item name="android:textColor">#ffffff</item>/>
<item name="android:textborderColor">#ff00ff</item>
</style>
</resources>
and use like this :
<Textview
android:id="#+id/tv"
style="#style/edt_text"
android:textColor="#616161"
/>
The title says it all: how can I style my PreferenceFragmentCompat. My v14/style.xml is
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:editTextStyle">#style/Widget.EditText.White</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>
</style>
<style name="Widget.EditText.White" parent="#android:style/Widget.EditText">
<item name="android:textColor">#ffffffff</item>
</style>
</resources>
The base theme has a black background - the preferences screen is then unreadable as I have black text on that black background.
I've tried many things but I cannot change the text colour.
What I've had to do is to set the fragment container background colour to white whilst the settings fragment is active. An ugly hack and not what I want to have to do.
To answer my own question: my v14/style.xml is now
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:editTextStyle">#style/Widget.EditText.White</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>
</style>
<style name="Widget.EditText.White" parent="#android:style/Widget.EditText">
<item name="android:textColor">#ffffffff</item>
</style>
<style name="PreferenceThemeOverlay.v14">
<item name="android:background">#color/settings_background</item>
<item name="android:textColor">#color/settings_text_colour</item>
<item name="android:textColorSecondary">#color/settings_text_colour_secondary</item>
</style>
</resources>
My problem is now to style a ListPreference.
Why is this so hard? If there is any documentation relating to styling preferences, it is well hidden. Grrrrrr!
Take a look at README for github project
Gericop/Android-Support-Preference-V7-Fix
I am using Accengage (Ad4Push) and I want to customize its dialog. Accengage team said that it is possible to change dialog style with custom theme and I did that. I can change textSize, textColor, windowBackground but I still see the grey color on Dialog. Please see my photo Here. (I haven't got enough reputations to post an image)
I want to change all background dialog to white, but I don't know which attribute I can use for this purpose.
This is the attribute I am using.
<style name="CustomDialogTheme" parent="#android:style/Theme.Dialog">
<item name="android:background">#color/background_holo_light</item>
<item name="android:divider">#color/background_holo_light</item>
<item name="android:dividerHorizontal">#null</item>
<item name="android:dividerVertical">#null</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textColorPrimary">#android:color/black</item>
<item name="android:buttonBarButtonStyle">#style/CustomDialogTheme.Button</item>
<item name="android:padding">2dp</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
<style name="CustomDialogTheme.Button">
<item name="android:background">#color/background_dark</item>
<item name="android:textColor">#color/background_holo_light</item>
<item name="android:layout_margin">8dp</item>
<item name="android:layout_marginLeft">16dp</item>
<item name="android:padding">8dp</item>
<item name="android:gravity">center</item>
</style>
How I can make background of dialog become white. (I only can change the style with custom style, can not change programmatically, because this dialog come from third party library)
In onCreate add this line.
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
checkout this post.
Dialog with transparent background in Android
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">
add this line in your theme (thanks to AAA)
<item name="android:windowBackground">#android:color/transparent</item>
full style:
<style name="CustomDialogTheme" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:background">#color/background_holo_light</item>
<item name="android:divider">#color/background_holo_light</item>
<item name="android:dividerHorizontal">#null</item>
<item name="android:dividerVertical">#null</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textColorPrimary">#android:color/black</item>
<item name="android:buttonBarButtonStyle">#style/CustomDialogTheme.Button</item>
<item name="android:padding">2dp</item>
</style>
I want to make my app to have several styles.
The style changes button style, textview color, and layout background color.
I have my button style in xml files.
And this is my code: style.xml (v21)
<style name="ThemeIndigo" parent="#android:style/Theme.Material.NoActionBar">
<item name="android:colorPrimary">#color/indigo</item>
<item name="android:colorPrimaryDark">#color/indigo</item>
<item name="android:navigationBarColor">#color/indigo_dark</item>
<item name="android:buttonStyle">#drawable/indigo_button</item>
<item name="android:background">#drawable/indigo_button</item>
</style>
This changes background color of all things on this layout.
How do I make my style to only change color of the buttons?
Please help. Thanks.
(Sorry for the bad english ;)
Try this style to change for just buttons in the app
<style name="ThemeIndigo" parent="#android:style/Theme.Material.NoActionBar">
<item name="android:buttonStyle">#style/MyButton</item>
</style>
<style name="MyButton" parent="android:Widget.Material.Button">
<item name="android:textSize">19sp</item>
<item name="android:layout_margin">0dip</item>
<item name="android:background">#ff0000</item>
</style>
Let's say I have multiple styles.xml files (with different names of course) for themes. Is it possible to choose which file the app should pull from?
White style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="mybutton">
<item name="android:layout_width">45dp</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:textColor">#202020</item>
<item name="android:textSize">20dp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#drawable/white_btnbg</item>
</style>
...
Black style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="mybutton">
<item name="android:layout_width">45dp</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textSize">20dp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#drawable/black_btnbg</item>
</style>
...
So then, in my layout xml all my button's styles would be set to "mybutton" and depending which theme the user chose it would pull from the coordinating file.
Since it isn't possible to change a view's style at runtime is it possible to do this? Or is there a better way (i'm sure there is) to change styles?
Use multiple styles with different names. Then you can set the backGround programmatically:
Button b = new Button(this);
b.setBackgroundResource(R.drawable.blabla);