Android Honeycomb CheckBox against white background cannot be seen - android

I am putting a CheckBox against a white background. It looks fine on pre-Honeycomb devices but on Honeycomb, it seems that the graphic has partial transparency and is white, so when the checkbox is unticked, you cannot see it.
I tried using the Theme.Holo.Light style as follows:
<CheckBox android:text="" style="#android:style/Theme.Holo.Light"
android:layout_marginLeft="5dip" android:id="#+id/checkBoxWifiOnly"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
This appears to have no effect. Am I typing the syntax wrongly?

You are applying the theme in a wrong way. Either apply #android:style/Theme.Holo.Light to the whole app/activity in the AndroidManifest.xml, or use #android:style/Widget.Holo.Light.CompoundButton.CheckBox as the style of your CheckBox. Also note that the "Holo" theme is available only on Honeycomb and higher.
I think that you'll have to apply the theme to the whole app, if you want the checkbox to have a different background. The thing is, that Widget.Holo.Light.CompoundButton.CheckBox and Widget.Holo.CompoundButton.CheckBox are the same and both extend the Widget.CompoundButton.CheckBox style, which has the "button" variable set by the theme attribute listChoiceIndicatorMultiple. This attribute's value is, in fact, different for light and dark theme.
I'd suggest you to create your own theme in values/themes.xml file, like this:
<style name="Theme.MyAwesomeApp" parent="#android:style/Theme.Light">
...
</style>
and in values-v11/themes.xml, like this:
<style name="Theme.MyAwesomeApp" parent="#android:style/Theme.Holo.Light">
...
</style>
and then set it in your AndroidManifest.xml, like this:
<application android:theme="#style/Theme.MyAwesomeApp" ... >
...
</application>
Maybe you should also read how the themes and styles work: https://developer.android.com/guide/topics/ui/themes.html

Related

How to set PreferenceFragmentCompat accentColor?

I'd like to override the accentColor used by v14 PreferenceFragmentCompat.
I'm using a pink accent color for the outer frame of my Android app. This creates problems in many situations as it causes standard controls to use an accent color that's close enough to red that the effect is disturbing. Be that as it may, I like the effect of having a pink FAB and button controls on the frame.
For child activities, I use a them with the standard teal accent color. However, I have a PreferenceFragment compat in a drawer on the main activity, and I cannot figure out how to override the main activity's accent color.
Things I have tried (none of which work):
Setting a theme on the frame of the fragment that receives the PreferenceFragmentCompat (doesn't work):
<FrameLayout android:id="#+id/preferenceFragmentFrame"
android:layout_width="match_parent" android:layout_height="0dp"
android:layout_weight="1"
android:theme="#style/AppTheme.TealAccentColor"
/>
where the AppTheme.TealAccentColor style provides an explicit teal acccentColor.
Setting the accentColor in a preference theme (doesn't work):
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="preferenceTheme">#style/MyPreferenceThemeOverlay</item>
</style>
<style name=MyPreferenceThemeOverlay parent="PreferenceThemeOverlay.v14.Material>
<item name="colorAccent">#color/colorAccentTeal</item>
</style>
Adding an accent color to preference-v14's PreferenceThemeOverlay (doens't work):
<!-- use the library's theme-->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="preferenceTheme">PreferenceThemeOverlay.v14.Material</item>
</style>
<!-- but add an accentColor item to the library's theme -->
<style name="PreferenceThemeOverlay.v14">
<item name="colorAccent">#color/colorAccentTeal</item>
</style>
No matter what I do, PreferenceFragmentCompat seems to take the pink accent color from the Activity's theme instead.
I'm sure it has something to do with a disconnect between the Activity's theme and a Fragment's theme. But there's no xml element for the fragment, since PreferenceFragmentCompat provides its own layout.
Maybe there's a way to do it programmatically with an override in the class that extends PreferenceFragmentCompat, but if there is, I can't imagine what it would be. Most of the attack points I can think of either have access to the internally-created layout, or have access to the layout after it has been created, which is too late.
A picture might help:
Have you tried overriding android:colorAccent instead of colorAccent?
Use the method you described as "Setting the accentColor in a preference theme", just change the attribute name.
The preference support library doesn't take into consideration appcompat at all, so
forget about appcompat attributes
color* attributes will only work on API 21, I think
If you want consistent behavior you can use my library Android Support Preference which aims to connect preference and appcompat support libraries.
Then you original style with colorAccent (unprefixed) will work as expected.

Themes in android

A create a simple Theme as
<style name='one'>
<item name='android:textColor'>#eea</item>
<item name='android:textSize'>20sp</item>
</style>
However on viewing in the emulator the screen goes black.when i do not apply theme the screen has a white background .
what really happens here.i am just starting with android.
In addition ,if a apply a theme to my activity then the attributes of the theme applies to all components of my activity say button,textfields and edittexts .
why would i then write
android:textSize=?android:textSize
to reference value from the theme for any button in my layout when the same value would already be applying.
is the syntax above the correct way to reference an attribute from my theme to assign to attribute for any view in my layout.
thanks
tejinder
Yeah, so you need to do a little more reading.
Let's start with the basics,
You need to understand the differente betweent an Attribute, a Style, and a Theme.
An Attribute is something that can be styled. For instance: android:textSize is an attribute that can have any value.
A Style is a set of specific attributes that will be applied to a Widget. They are defined
in your /values/styles.xml
For instance:
<style name="normalTextThin" parent="android:Widget.Holo.Light.TextView">
<item name="android:gravity">left|center_vertical</item>
<item name="android:padding">8dp</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textSize">16sp</item>
</style>
The styles can be applied either as part of a theme or directly as theme-independent.
Theme-indepentent styling of a widget is like this:
<TextView
android:id="#+id/text"
style="#style/normalTextThin"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
You are then theming only that one TextView.
A Theme is a collection of Styles that can be applied to a part of your UI, such a a whole Activity, or your whole Application.
For instance:
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:editTextStyle">#style/EditTextAppTheme</item>
<item name="android:buttonStyle">#style/ButtonAppTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonAppTheme</item>
</style>
Here, we are declaring that all EditText in your application will use the style named EditTextAppTheme, and so forth and on. When done like this, in order to actually have the theme be active, you declare it in the manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
That means that you are not required to declare the style on each widget you create.
<EditText
android:id="#+id/input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/hint_search">
<requestFocus />
</EditText>
That widget right there would already be styled using EditTextAppTheme without the need of you explicitely declaring so.
I recommend you try to read on what attributes can be styled, how to style them, and so forth and on.
If you don't want to though, it's fine, you can still get a lot done with the following tools for styling:
ActionBarStyleGenerator to help you create styles for the ActionBar.
Android Holo Colors to help you style standard widgets.
Hope that helps.
Additional Info
Let me clarify on the whole ?attr/attributeName
The ? means that the system will choose the specific attributeName value for the current Configuration (not specific to different themes). This should be used only when you want the value to be different on different configurations. For example:
?android:attr/actionBarSize
This line is a dimension, and it will be different not based on the current theme, but on the current device screen size and orientation (values, values-land, values-sw600dp).
It's important to know that specifying ?android: means you are accessing preset Android values, not yours. If you have or want to create and use your own attribute values for specific configurations, you must do the following:
Create a file named attrs.xml on your /values/ folder.
Declare the desired custom attribute:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<attr name="my_custom_attr" format="reference" />
</resources>
Declare a value for the custom attribute, let's say on your own theme.
<style name="AppTheme" parent="android:Theme.Light">
<item name="my_custom_attr">#resource_type/resource_name</item>
<item name="android:editTextStyle">#style/EditTextAppTheme</item>
<item name="android:buttonStyle">#style/ButtonAppTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonAppTheme</item>
</style>
And then you can use it on the Widget you'd like:
Hope that clears things out.
EDIT 2
For a better answer to your question, please update your question. And like I said, read more on how to properly create styles.
The Theme named 'one', what do you want to apply it to? An activity, a Widget, the whole Application?
How are you applying the theme? Show the lines of code where you specify the usage of theme 'one'.
Your theme as you specified is simply not a properly constructed theme/style.
<style name='one'>
<item name='android:textColor'>#eea</item>
<item name='android:textSize'>20sp</item>
</style>
This says absolutely nothing, and it is definitely not suitable for an Activity-level theme. The reason you specify a parent is so your theme can inherit all of the attributes from the parent, and then you specifiy which ones to change.
For instance, if you want to use your theme and have a light background, do this:
<style name='one' parent="android:Theme.Holo.Light>
<item name='android:textColor'>#eea</item>
<item name='android:textSize'>20sp</item>
</style>
But even here, despite the fact that it will apply, you don't want to have the same text color and size for the whole application do you? That'd be nonsense, different text color and sizes account for a big part of the user experience, so rather than setting those values from what we can refer to as the main style, we can create substyles and apply them to certain widgets.
I can't really go any more detailed that what I already have, the above explains how to accomplish Widget-specific styling, and activity/application level theming.
For a complete start-up guide, read the Android Developer Site, try the test styles declared there, see how they work, and until then try to create your own, don't try to create something out of nowhere if no reading has been made.

override standard style with ABS

In my AndroidManifest file i do not declare a theme.
The result is:
black background and ABS with blue background, also states of list item's is blue.
thats fine.
now i want to make to set the indeterminateProgressStyle to Widget.ProgressBar.Small
Therefore i have to declare my own style like this:
<style name="Custom" parent="??">
<item name="android:actionBarStyle">#style/ActionBarIPS</item>
</style>
what should i enter in the parent parameter?
i want all style behaviors like before (black background with blue ABS and blue list item states etc as it is defined when i dont declare a theme attribute in AndroidManifest.
EDIT:
i also need to know this parent's value:
<style name="ActionBarIPS" parent="ABS with blue background">
<item name="android:indeterminateProgressStyle">#style/IndeterminateProgress</item>
</style>
the version without a style in manifest:
the version with custom style and parent=Theme.Sherlock
i want the first version with indeterminate spinner set to "small"
It's depend to your current style, It can be Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.ForceOverflow and etc, e.g:
<style name="Custom" parent="Theme.Sherlock or Theme.Sherlock.Light">
<item name="android:actionBarStyle">#style/ActionBarIPS</item>
<item name="android:indeterminateProgressStyle">#style/IndeterminateProgress</item>
</style>
Note: You must declare this style in style.xml in your values directory.
Edited:
You got blue ActionBar without using ABS because you're using Samsung TouchWiz default UI.
If you install your APK in non-samsung devices you won't see this blue action bar, But If you are forced to have blue actionbar then put the following image in your drawable directory and set it as your actionbar background through:
getSupportActionBar().setBackgroundDrawable(getResources()
.getDrawable(R.drawable.TouchWiz_ActionBar_Bg));
Try to use "Theme.Sherlock" as a parent. Also I suggest to add:
<item name="actionBarStyle">#style/ActionBarIPS</item>

Holo light theme not setting on button

I am building a sample application based on latest version of Android OS..As per instructions given here I am trying to give holo:light theme to only one button in my application. How do i do it ? I have created a myStyles.xml in res/values folder but I am not able to find property to apply holo-light theme.
This is what i have in myStyles.xml file
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="mybutton" parent="android:Theme.Holo.Light">
<item name="android:background">#android:color/holo_orange_light</item>
<item name="android:textColor">#android:color/holo_blue_dark</item>
</style>
</resources>
this is i have in my activity.
<Button
android:id="#+id/button1"
style="#style/mybutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lol" />
I can confirm that backgroundcolor and textcolor are getting applied...(done this for testing purpose).
Currently, If i add android:theme="#android:style/Theme.Holo.Light" to AndroidManifest.xml, holo light theme is applied to entire application. However, I want this theme to be applied for only few controls ( in this case a single button control).
A theme is a style applied to an entire Activity or application, rather than an individual View.
Thus, what you are asking for is not possible. That being said, it seems odd that you would want to do this anyway. I suggest applying the holo theme to your entire app, and then customizing your Buttons only if you really need to. This is probably what the user will expect from your application.

Android preference title/summary text style

I have a couple custom preference items -- one that displays a swatch of the currently selected color, and another one that displays a thumbnail.
I have a custom layout for these that matches up very well, and have found that I can make the text appearance match by using android:textAppearance="?android:attr/textAppearanceLarge" as part of the TextView's xml. The problem is, while these generally look fine, they must not be the appearance the 'official' preferences use, since the colors end up wrong on some devices. In particular I'm porting my application to the Nook Color, and it uses a light grey background and black text color on the preference screen instead of black background/light grey text. My text color in this situation stays the same, but the rest of my layout is themed appropriately.
I'm really unsure what I'm supposed to do here to make my text match up with the 'official' theme. Should I be using obtainStyledAttributes and running though my layout to set things? The tutorials I've seen on using that so far have been really baffling, and it seems like there must be a textAppearance or style I can set in the XML to fix this.
You've to define your own application theme which inherits from the official theme you want. Actually, you can just define a theme MyTheme extending the Theme.Light for example.
Create an res/values/styles.xml file like that:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="#android:style/Theme.Light">
</style>
</resources>
Then, you just have to apply your theme using the android:theme attribute of the application entity of your AndroidManifest.xml:
<application android:theme="#style/MyTheme">
[...]
</application>

Categories

Resources