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.
Related
I have created a style:
<style name="Button_Display">
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">88dip</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
</style>
I want that all the Button's in my application will look like declared above.
My question is how can i combine the Button_Display style inside a theme so all the Buttons in my app will have this look and feel?
https://developer.android.com/guide/topics/ui/look-and-feel/themes
In styles.xml create your own button style. Choose whatever parent style matches your need the best. Then overwrite all the necessary parameters.
<style name="myButtonStyle" parent="#style/Widget.AppCompat.Button">
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">88dip</item>
...
</style>
Then set this as default button style in your theme.
<style name="AppTheme" parent="Theme.AppCompat....">
<item name="buttonStyle">#style/myButtonStyle</item>
...
</style>
Now all Buttons will have the parameters you specified in your style.
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'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.
My theme is:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowContentOverlay">#null</item>
<item name="actionBarTheme">#style/MyActionBarTheme</item>
<item name="actionBarStyle">#style/MyActionBarStyle</item>
<item name="circularProgressBarStyle">#style/CircularProgressBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#color/white</item>
<item name="actionBarTabBarStyle">#style/MyActionBarTab</item>
</style>
I don't see any style here that can affect my button text color because they are for action bar styling. But I still cannot change my button text color in layout file:
<Button
...
android:textSize="22sp"
android:textColor="#color/yellow"
... />
I can change textSize here but not the textColor. Anyone can tell me why? Shouldn't it be the highest priority for styling? (That means overriding style.xml config if there is one). Please correct me if I am wrong. Much appreciation!
This is what you should be doing:
android:textColor="#android:color/yellow"
instead of
android:textColor="#color/yellow"
button.setTextColor(getApplication().getResources().getColor(R.color.green));
button.setTextColor(Color.parseColor("#ff1100"));
add this into your style
<item name="colorButtonNormal">#color/colorPrimary</item>
or
you can add property android:background to button class like this
<Button
...
android:textSize="22sp"
android:background="#color/yellow"
... />
As TejjD said :
This is what you should be doing:
android:textColor="#android:color/yellow" instead of
android:textColor="#color/yellow"
You have to define your custom color in Colors.xml file.
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