How do I find all possibillities for Androids "Theme XML Style"? - android

The following file defines the base style used by my application:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Snapchat" parent="????" >
<item name="android:colorPrimaryDark">#color/Snapchat_violet</item>
<item name="android:colorPrimary">#color/Snapchat_blue</item>
<item name="android:colorAccent">#color/Snapchat_blue</item>
<item name="android:colorBackground">#color/Snapchat_white</item>
<item name="android:colorForeground">#color/Snapchat_yellow</item>
<item name="android:navigationBarColor">#color/Snapchat_grey</item>
</style>
</resources>
I want to use a standard theme as the parent to inherit from, but I can't find a listing of all standard themes and their corresponding xml names/paths.
I'm sorry if this is a newbish question, but I just can't find it in the android documentation.

check out following links it will help you
Theme.xml
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml
Style.xml
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/styles.xml

You can define multiple styles per file using tag but each style will have its name that uniquely identifies the style. Android style attributes are set using tag as shown below −
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomFontStyle">
<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:typeface">monospace</item>
<item name="android:textSize">12pt</item>
<item name="android:textColor">#00FF00</item>/>
The value for the can be a keyword string, a hex color, a reference to another resource type, or other value depending on the style property.
Using Styles
Once your style is defined, you can use it in your XML Layout file using style attribute as follows −
<TextView
android:id="#+id/text_id"
style="#style/CustomFontStyle"
android:text="#string/hello_world" />
</LinearLayout>
To implement a custom theme create or edit MyAndroidApp/res/values/themes.xml and add the following −
<resources>
...
<style name="MyCustomTheme" parent="android:style/Theme">
<item name="android:textColorPrimary">#ffff0000. </item>
</style>
...
</resources>
In your AndroidManifest.xml apply the theme to the activities you want to style −
<activity
android:name="com.myapp.MyActivity"
....
android:theme="#style/MyCustomTheme"
/>
Your new theme will be applied to your activity.
You can also have a look at http://www.tutorialspoint.com/android/android_styles_and_themes.htm

See style, stylable and attr.

Related

Allow styles to be themed

I have a simple problem. I'd like to provide multiple themes for my UI that a user can switch between
The problem is that I can use a theme that styles primitive UI classes, or I can use a style directly on an XML layout element, but I can't define a style that will then change based on the theme I have applied. Not all of the styling I want to do is based on the primitive type.
I would say that what I want to do is similar to using a CSS selector to style a class or ID, but themes only allow you to style an element name.
The best I can do right now is have a base style that inherits from EITHER of the actual styles I've built, as below:
My res/values/style.xml
// All styles have to be subclassed here to be made generic, and only one
// can be displayed at a time. Essentially, I'm doing the same thing as setting
// a theme does, but for styles. If I have 50 styles, I have to have 50 of
// these for each theme, and that's not DRY at all!
<style name="MyHeaderStyle" parent="MyHeaderStyle.Default"/>
<!--
<style name="MyHeaderStyle" parent="MyHeaderStyle.Textures"/>
-->
<style name="MyHeaderStyle.Default">
<item name="android:background">#android:color/background_dark</item>
</style>
<style name="MyHeaderStyle.Textures">
<item name="android:background">#drawable/header_texture</item>
</style>
Usage in my layout.xml:
<!-- Note that I can't use a theme here, because I only want to style a
SPECIFIC element -->
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#style/MyHeaderStyle"
android:gravity="center">
</LinearLayout>
Try this method:
1) Define your own res/values/attrs.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="AppTheme">
<attr name="myLinearLayoutStyle" format="reference" />
</declare-styleable>
</resources>
2) Assign the above attr to you LinearLayout
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?attr/myLinearLayoutStyle"
android:gravity="center">
</LinearLayout>
3) Assign a concrete style to this attr:
<style name="AppLightTheme" parent="android:Theme.Holo.Light">
<item name="#attr/myLinearLayoutStyle">#style/lightBackground</item>
</style>
<style name="AppTheme" parent="android:Theme.Holo">
<item name="#attr/myLinearLayoutStyle">#style/darkBackground</item>
</style>
<style name="lightBackground">
<item name="android:background">#D1CBF5</item>
</style>
<style name="darkBackground">
<item name="android:background">#351BE0</item>
</style>
Hope I understood correctly your question.

How to change the default color of DatePicker and TimePicker dialog in Android?

Is there any way to change the default color of DatePicker and TimePicker dialog?
This is the code I tried
<DatePicker
style="#style/date_picker"
android:background="#6495ED"
android:id="#+id/DatePicker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip" />
<TimePicker
android:id="#+id/TimePicker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip" />
Below two line only changing the background color, I want to change the default silver color of both date and time picker. Any help please.
style="#style/date_picker"
android:background="#6495ED"
The best way to change the picker dialog is by adding custom style to it.
<style name="TimePickerTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#color/color_primary</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
TimePickerDialog timePicker = new TimePickerDialog(mContext, R.style.TimePickerTheme, fromListener, hour, min, false);
Worked perfectly for me.
You have to create a custom theme and save it in some directories to finally set this theme as the default one for the app
First, in values add a themes.xml like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAppTheme" parent="#android:style/Theme.Light.NoTitleBar">
<!-- Any customizations for your app running on pre-3.0 devices here -->
</style>
</resources>
Then, create a directory with the name "values-v11" (Android 3.0+ ) in the res directory and put a themes.xml like this
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAppTheme" parent="#android:style/Theme.Holo.Light">
<!-- Any customizations for your app running on 3.0+ devices here -->
</style>
</resources>
Finally, create a directory with the name "values-v14" (Android 4.0+) in the res directory and create a themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAppTheme" parent="#android:style/Theme.DeviceDefault.Light.NoActionBar">
<!-- Any customizations for your app running on 4.0+ devices here -->
</style>
</resources>
Finally in your manifest.xml
<application
...
android:theme="#style/MyAppTheme">
I think there is no way to change the grey color of the old native picker widgets easily in XML.
I propose you use the library HoloEverywhere so that DatePicker and TimePicker look really nice on all Android platforms 2.1+.
you can change theme of your date-picker by changing theme like this.
change items according to you.
<style name="date_picker" parent="#android:style/Widget.DeviceDefault.DatePicker">
<item name="android:divider">#drawable/dialog_divider</item>
change items according to you.
and set this theme to your data-picker style
style="#style/date_picker"
For Date Picker add this codes to color.xml
<color name="mdtp_accent_color">#070B82</color>
<color name="mdtp_accent_color_dark">#0D105E</color>
For both you can define style in style.xml
<style name="TimePickerTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/blue</item>
</style>
and set style in xml:
android:theme="#style/MyAppTheme"
or programically:
TimePickerDialog timePicker = new TimePickerDialog(mContext, R.style.TimePickerTheme, fromListener, hour, min, false);

How to reference a style in a custom theme

I have a login screen that is branded differently for different builds of my application. I need the background image to be different in the layout file for this screen, so I want to point to a different style for the top level container. I'm a bit at a loss at how to do this.
I have declared a styleable something like:
<resources>
<declare-styleable name="ThemeBase">
<attr name="loginPageContainerStyle" format="reference" />
</declare-styleable>
</resources>
I have several different themes for the application, as such:
<resources>
<style name="ThemeBase" parent="android:style/Theme.Light" />
<style name="ThemeOne" parent="ThemeBase">
<item name="loginPageContainerStyle">#style/loginPageContainerThemeOne</item>
</style>
<style name="ThemeTwo" parent="ThemeBase">
<item name="loginPageContainerStyle">#style/loginPageContainerThemeTwo</item>
</style>
</resources>
And I have defined the following styles:
<resources>
<style name="loginPageContainerThemeOne">
<item name="android:background">#drawable/background_theme_one</item>
</style>
<style name="loginPageContainerThemeTwo">
<item name="android:background">#drawable/background_theme_two</item>
</style>
</resources>
And finally a login.xml file something like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/loginRoot"
style= [ ? WHAT GOES HERE ? ]
android:gravity="center_horizontal"
android:orientation="horizontal">
[ LAYOUT STUFF ... ]
</LinearLayout>
Am I doing anything wrong? Can this be done this way?
Ok I figured it out, the style reference should be:
style="?attr/loginPageContainerStyle"
Figured I would share.

No style ViewPagerIndicator in combination with SherlockActionBar

I'm trying to implement the ViewPagerIndicator with SherlockActionBar. It works: I can slide the fragments, but the style doesn't work!
It looks like this:
related topic: https://github.com/JakeWharton/Android-ViewPagerIndicator/issues/66
I know what's going wrong:
In the sample of VPI, the style of a page is set in AndroidManifest.xml by (for example)
<activity
android:name=".SampleTabsDefault"
android:theme="#style/Theme.PageIndicatorDefaults">
</activity>
But when I add that android:theme element to my own Manifest.xml I get the following exception:
03-16 11:06:24.400: E/AndroidRuntime(483): Caused by: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
I've also tried to copy all the style-information to styles.xml, but that also doesn't work.
Can you tell me how to set a style to the VPI?
Thank you!
EDIT:
Now I've added
<activity
android:name=".SampleTabsDefault"
android:theme="#style/StyledIndicators">
</activity>
to my Manifest.xml
and the following style in styles.xml
<style name="Theme.BataApp" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="StyledIndicators" parent="Theme.BataApp">
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
</style>
Result: I don't get any Exception, see the style, but I now I can't see any fragments :(
The code of the activity can be found here: http://pastebin.com/hsNgxFDZ
Screenshot of current page with style:
In order to see the Fragments, you'll have to somehow extend an Android base-theme. In order to see the ViewPagerIndicator, you'll have to somehow include those style-definitions. The answer is to create your own theme that extends the ActionBarSherlock-theme (which extends the Android base-themes), and implements the ViewPagerIndicator-styles.
Example:
<style name="myTheme" parent="#style/Theme.Sherlock">
<!-- If you want to use the default ViewPagerIndicator-styles, use the following: -->
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
<!-- If you want to implement your custom style of CirclePageIndicator, do it like so: -->
<item name="vpiCirclePageIndicatorStyle">#style/myCirclePageIndicator</item>
<!-- Put whatever other styles you want to define in your custom theme -->
</style>
<style name="myCirclePageIndicator" parent="Widget.CirclePageIndicator">
<item name="fillColor">#color/my_custom_circle_indicator_fill_color</item>
</style>
Then in your Manifest, set android:theme="#style/myTheme" to the <application> or to your <activity>s.
Note that you don't have to include all 4 "vpi..."-styles; you only have to include those that you use. E.g. if you're only using the CirclePageIndicator, you only have to include <item name="vpiCirclePageIndicatorStyle">...</item> and can leave out the other 3 item declarations.
I accidentally removed android:layout_weight="1" when adding styles.
So for other who want to implement VPI with ABS:
layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.viewpagerindicator.TabPageIndicator
android:id="#+id/indicator"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
style="#style/StyledIndicators" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
styles.xml:
<style name="Theme.BataApp" parent="Theme.Sherlock.Light.DarkActionBar">
etc.
</style>
<style name="StyledIndicators" parent="Theme.BataApp">
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
</style>
Thank you #Reinier! :D

Override all form element styles like HTML+CSS

In HTML/CSS you can override all paragraphs by defining p in CSS
I.e.
p { color: blue;
}
Can you do mimc this in Android? I'd like to define my set of styles for all form elements in styles.xml and then every layout I write would use these properties.
At the moment I have to specify the style in the layout: i.e
<EditText android:id="#+id/address1" style="#style/EditText" />
Which seems a bit redundant (and error prone).
Thanks,
John
You have to create an xml file which defines the style that you want, and store it in res/values folder.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CodeFont" parent="#android:style/TextAppearance.Medium">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
</style>
</resources>
This is an example of an style, once you have your style. you can applay it to every view by doing something like this:
<TextView
style="#style/CodeFont"
android:text="#string/hello" />
This example is from:
http://developer.android.com/guide/topics/ui/themes.html

Categories

Resources