I'm making an android app, and I'm using Spinners in Dialog Mode, defined as follows :
<Spinner android:id="#+id/new_order_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/SpinnerTheme"
style="#style/UnderlinedSpinner"
android:layout_below="#+id/new_order_hint_address"
android:prompt="#string/myString"
android:spinnerMode="dialog"
android:layout_marginBottom="5dp" />
where the styles are
<style name="SpinnerTheme">
<item name="colorControlNormal"> #color/colorPrimaryDark </item>
<item name="android:textColorSecondary"> #color/colorPrimaryDark </item>
<item name="android:colorControlHighlight"> #color/colorPrimaryDark </item>
<item name="android:colorControlActivated"> #color/colorPrimaryDark </item>
<item name="android:minHeight"> 35dp </item>
<item name="android:showDividers"> middle </item>
<item name="android:divider"> #color/colorAccent </item>
<item name="android:dividerHeight"> 0.5dp </item>
</style>
<style name="SpinnerLabel" parent="TextAppearance.Design.Hint">
<item name="android:paddingLeft">#dimen/input_label_horizontal_spacing</item>
<item name="android:paddingRight">#dimen/input_label_horizontal_spacing</item>
<item name="android:textSize"> 14sp </item>
<item name="android:textColor">#color/hintText</item>
</style>
<style name="UnderlinedSpinner" parent="Base.Widget.AppCompat.Spinner.Underlined"/>
In API <23, everything works fine, but in API 23, the prompt is not shown. I've tried setting in from the java code, I've read all the similar questions and answers and have had no luck whatsoever.
Thanks in advance
Ok, after a lot more of trial and error, I found out that the issue was in fact that the color of the prompt text was the same as the color of the background of the prompt (both white).
The reason behind it relays on the "textColorPrimary", which I'm not setting in the style of the spinner, but I did set in the style of the Tabhost where it is located. It looks like it inherited this property.
Therefore, the solution is just adding that parameter to the style, with the color desired.
The only thing I'm not sure is why this only happens in APIs > 23, and not the others.
Related
for example i have a style
<style name="apptheme.home">
<item name="textColorAnswer"> #Color/blue </item>
<item name="layoutColorAnswer"> #Color/red </item>
</style>
how to change the color of textColorAnswer and layoutColorAnswer with android java code
The color values in styles file are immutable.
They can only be changed manually while developing and not during the runtime of the application.
If you want to change the theme of the application you need to create different styles with different names.
Eg.
<style name="RedTheme">
<item name="textColorAnswer"> #Color/blue </item>
<item name="layoutColorAnswer"> #Color/red </item>
</style>
<style name="BlueTheme">
<item name="textColorAnswer"> #Color/red </item>
<item name="layoutColorAnswer"> #Color/blue </item>
</style>
After defining all the styles then you need to call these themes using
setTheme(R.style.BlueTheme);
OR
getTheme().applyStyle(R.style.RedTheme, true);
These methods should be called before the
setContentView(R.layout.main);
OR
//for data binding layouts
binding = DataBindingUtil.setContentView(this, R.layout.main);
setTheme() and getTheme() method will only work before setting the
View of the layout else the app will crash.
Styles.xml:
<style name="windowTitleBackgroundStyle">
<item name="android:background">#A4D05F</item>
</style>
<style name="windowTitleStyle">
<item name="android:drawableLeft">#drawable/smartlogo</item>
<item name="android:textColor">#C6C09C</item>
<item name="android:padding">12dip</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">16sp</item>
</style>
I am customizing my titlebar in android using eclipse ide. I can also see my image that is being set by the drawableleft, however it is too big. Do you know how to set the width and size of the drawableleft?
you can use a xml-drawable, that you can customise as you wish.
You can find here some examples and a lot others on net.
Alternatively, you can also create a simple XML, containing a view, image etc, like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="#drawable/icon"
android:width="#dimen/icon_size"
android:height="#dimen/icon_size"
/>
</layer-list >
,and use this as your drawableLeft.
Hope this helps!
if API level 23 and higher you can change like this
<item
name="android:drawableLeft"
android:drawable="#drawable/smartlogo"
android:height="24dp"
android:width="24dp"/>
I like to show alert like this:
And when I click the first settings icon, show an alert like this one:
To achive that you have to group the subitems and embed in a one menu item.
Here is an example you can refer.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/id_group1"
android:icon="#drawable/v3_actionbar_setting"
android:orderInCategory="120"
android:showAsAction="always"
android:title="#string/action_settings">
<menu>
<item
android:id="#+id/subitem1"
android:icon="#drawable/actionbar_settings"
android:title="subitem 1"/>
<item
android:id="#+id/subitem2
android:icon="#drawable/image2"
android:title="subitem 2">
</item>
</menu>
</item>
<item
android:id="#+id/group2"
android:icon="#drawable/group2"
android:orderInCategory="90"
android:showAsAction="always"
android:title="group 2">
<menu>
<item
android:id="#+id/subitem21"
android:icon="#drawable/subitem1"
android:title="subitem1"/>
<item
android:id="#+id/subitem22"
android:icon="#drawable/sub2"
android:title="sub2"/>
</menu>
</item>
Hope this helps :)
Take a good look at this: Android Menus
You'll possibly find all you need.
I have an xml file on my PC. Something like this:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/title_text"
style="?textTitle"/>
In attrs.xml is defined:
<attr name="textTitle" format="reference" />
In an style.xml file is written:
<style name="text_title_bl">
<item name="android:textColor">#FFF</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">24sp</item>
<item name="android:gravity">center_vertical|left</item>
<item name="android:paddingLeft">5sp</item>
<item name="android:shadowDx">1.0</item>
<item name="android:shadowDy">1.0</item>
<item name="android:shadowRadius">1</item>
<item name="android:shadowColor">#DDD</item>
<item name="android:background">#FF004488</item>
</style>
My question is how does it work, that eclipse knows that "?textTitle" belongs to this style above? Or why is "?textTitle" = "text_title_bl"? It is an example which works with multiple themes.
Thank for your help:)
The ? means "look this up in the current theme, and use that value". In this case, that value from the theme is then used as the style name.
Your theme has an entry with the key "textTitle" and the value "text_title_bl". If you changed this in your theme, the textview would use a different style.
I have the following preference screen in my app
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:key="edittexvalue"
android:id="#+id/edittextvalue"
android:title="Title Here"
android:summary="Summary Here"
android:defaultValue="Some Value"/>
<Preference
android:key="customPref"
android:title="Title Here"
android:summary="Summary Here"/>
</PreferenceScreen>
All of that works just fine however my app i have custom backgrounds and text colors/sizes but i can't figure out how to format the PreferenceScreen I assume you point this at another xml? but can't figure out the code i need and what changes should be made. The main concern is the background color the text is fine i guess but the background just doesn't match the rest of my app. So i'd like to set a custom background color lets say red for now (#ff0000)
I thank anyone that can help me with this problem
You can to apply a theme to it in your manifest, for example
<activity android:name=".Settings"
android:theme="#style/YourStyle"/>
and in your styles.xml (if you dont have one, create it in the values folder)
you can modify whatever you need
For example
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YourStyle" parent="android:Theme.Light">
<item name="android:listViewStyle">#style/Widget.ListView</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="Widget" parent="android:Widget">
</style>
<style name="Widget.ListView">
<item name="android:background">#color/white</item>
<item name="android:divider">#color/gray_division</item>
<item name="android:dividerHeight">2dip</item>
</style>
</resources>
I hope this helps