I am creating style for all edittext in teme.
<style name="edittextStyle">
<item name="android:drawablePadding">10dp</item>
<item name="android:background">#drawable/white_round</item>
<item name="android:textColor">#color/black</item>
<item name="android:textColorHint">#color/gray</item>
<item name="android:singleLine">true</item>
<item name="android:padding">5dp</item>
<item name="android:gravity">center_vertical</item>
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:editTextStyle">#style/edittextStyle</item>
<item name="android:textSize">#dimen/font_medium</item>
</style>
It's working as expected and all edittexts are styled with white background. But they are not getting Input.
If I put style attribs directly to edittext , it's getting input. What am I missing ?
Got answer from #Alex.F , this did the trick.
change
<style name="edittextStyle">
to
<style name="edittextStyle" parent="Widget.AppCompat.EditText">
Just in case anyone stumbles upon a similar issue. When customizing a widget like edittext the best way to avoid problems is to inherit a parent style like Widget.DeviceDefault.EditText, for example.
Related
I want to change the background of alert dialog title in theme.
I do following changes in theme:
<style name="NgTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:dialogTheme">#style/NgDialogTheme</item>
<item name="android:alertDialogTheme">#style/NgAlertDialogTheme</item>
</style>
<style name="NgDialogTheme" parent="#android:style/Theme.Holo.Light.Dialog">
<item name="android:background">#android:color/transparent</item>
<item name="android:windowTitleStyle">#style/NgWindowTitleStyle</item>
</style>
<style name="NgAlertDialogTheme" parent="#style/NgDialogTheme">
</style>
<style name="NgWindowTitleStyle" parent="android:TextAppearance.Holo.DialogWindowTitle">
<item name="android:background">#318d99</item>
<item name="android:textColor">#fff</item>
</style>
I expected that background of title becomes #318d99. But only background of text is #318d99:
How can I change white frame around the title to #318d99?
Also the frame around the dialog isn't transparent. How can I fix it?
There are some valuable posts about this already and very closely related to your question.
Google's post on customizing this is possibly worth looking at first:
https://sites.google.com/site/androidhowto/how-to-1/customize-alertdialog-theme
Take a look at this blog post:
http://blog.supenta.com/2014/07/02/how-to-style-alertdialogs-like-a-pro/
Specifically, go to Part 5: Styling the Background.
To summarize, they suggest that you will probably have to
Stop inheriting from Holo
Give your main theme an alertDialogStyle
Then create a style with the following attributes, which you can get a reference to here: http://developer.android.com/reference/android/R.styleable.html#AlertDialog
You'll want to create a new style that inherits from the default alertdialog theme (this is discussed in both posts I mentioned above):
<style name="CustomDialogTheme" parent="#android:style/Theme.Dialog">
<item name="android:bottomBright">#color/white</item>
<item name="android:bottomDark">#color/white</item>
<item name="android:bottomMedium">#color/white</item>
<item name="android:centerBright">#color/white</item>
<item name="android:centerDark">#color/white</item>
<item name="android:centerMedium">#color/white</item>
<item name="android:fullBright">#color/orange</item>
<item name="android:fullDark">#color/orange</item>
<item name="android:topBright">#color/blue</item>
<item name="android:topDark">#color/blue</item>
</style>
I have an AlertDialog with buttons which I'd like to set to bold. I find the default style to be very thin:
but when I set the style as such:
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:textColorPrimary">#color/gray_dark</item>
<item name="colorAccent">#color/blue</item>
<item name="android:buttonStyle">#style/buttonStyle</item>
</style>
<style name="buttonStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textStyle">bold</item>
</style>
I find the result to be, erhm, much bolder than I'd like:
I was aiming for something like this:
The screenshot is from WhatsApp. Are they using a different font or is it something I can replicate just by styling my XML file?
Based on the answer here, it seems that the correct style for what I want to achieve is adding these lines to the button style:
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textStyle">normal</item>
Now I have the wanted "not so bold" look!
I'm trying to change the style for the Spinner's top divider, but without success.
I can only get that to work:
http://s18.postimg.org/qbg7920mh/spinner.png
Is is possible? What item should I modify?
<style name="AppTheme" parent="AppBaseTheme">
<!--item name="android:spinnerItemStyle">#style/SpinnerItem</item-->
<!--item name="android:spinnerDropDownItemStyle">#style/SpinnerDropDownItem</item-->
<!--item name="android:dropDownItemStyle">#style/TestSpinnerItemStyle</item-->
<item name="android:dropDownListViewStyle">#style/TestSpinnerStyle</item>
</style>
<style name="TestSpinnerItemStyle" parent="android:style/Widget.ListView.DropDown">
<item name="android:divider">#00b54a</item>
<item name="android:dividerHeight">5dp</item>
</style>
By looking at your code, there must be an obvious error!
Rename TestSpinnerItemStyle to TestSpinnerStyle in second part like:
<style name="TestSpinnerStyle" parent="android:style/Widget.ListView.DropDown">
...
</style>
I'm want to change the up icon with applying the following style to my activity, but it doesn't work and but I still get the default black '<' icon.
Can anyone find out what is missing here?
<style name="AppTheme.ActionBar" parent="#style/Theme.Sherlock.Light">
<item name="actionBarStyle">#style/actionBarStyle</item>
<item name="android:actionBarStyle">#style/actionBarStyle</item>
</style>
<style name="actionBarStyle" parent="#style/Widget.Sherlock.Light.ActionBar.Solid">
<item name="android:background">#drawable/header_bar</item>
<item name="background">#drawable/header_bar</item>
<item name="android:homeAsUpIndicator">#drawable/up_indicator</item>
<item name="homeAsUpIndicator">#drawable/up_indicator</item>
<item name="android:displayOptions">homeAsUp|showHome</item>
<item name="displayOptions">homeAsUp|showHome</item>
</style>
If I remember correctly, I worked around this issue by moving you should move the android:homeAsUpIndicator and homeAsUpIndicator elements into the main theme declaration. In other words, try:
<style name="AppTheme.ActionBar" parent="#style/Theme.Sherlock.Light">
<item name="actionBarStyle">#style/actionBarStyle</item>
<item name="android:actionBarStyle">#style/actionBarStyle</item>
<item name="android:homeAsUpIndicator">#drawable/up_indicator</item>
<item name="homeAsUpIndicator">#drawable/up_indicator</item>
</style>
<style name="actionBarStyle" parent="#style/Widget.Sherlock.Light.ActionBar.Solid">
<item name="android:background">#drawable/header_bar</item>
<item name="background">#drawable/header_bar</item>
<item name="android:displayOptions">homeAsUp|showHome</item>
<item name="displayOptions">homeAsUp|showHome</item>
</style>
Not sure whether I also had to move up the displayOptions, but you may want to give that a go too in case above doesn't work right away.
By the way, I find naming a style AppTheme.ActionBar and then inheriting from Theme.Sherlock.Light rather confusing. If it were an ActionBar specific style, I would've expected something like Widget.Holo.Light.ActionBar (or any of the other widget styles) as the parent. If it's your main theme, I'd name it accordingly. Up to you of course.
Edit: Updated answer after Jake's comment.
I am trying to apply default styling for all the listViews from style.xml
Please note at some places I am using nested listViews.
In style.xml
<style name="Theme.MyTheme" parent="Theme.Sherlock.Light.ForceOverflow">
<item name="android:windowContentOverlay">#null</item>
<item name="android:listViewStyle">#style/awesomeListViewStyle</item>
</style>
<style name="awesomeListViewStyle" parent="#android:style/Widget.ListView">
<item name="android:fadingEdge">none</item>
<item name="android:background">#color/orange</item>
<item name="android:divider">#EEEEEE</item>
</style>
This has no effect. In the Manifest Theme.MyTheme as my default theme.
Please advice :)
As mentioned in another answer as Bhavin and Mark pointed out, in your style you should also add
<item name="android:dividerHeight">1px</item>