Android 5.0 - checkboxes in preferences are not visible - android

I'm in the process of upgrading my app to Android 5.0 Lollipop design based on AppCompat v21.
Everything works fairly well but I hit a problem with the preferences screen where checkboxes are not visible. They are on the screen and I can see them when the whole section gets highlighted when it's touched. Functionality is fine and preferences are updated successfully.
Everywhere else in the app checkboxes display without any problems.
Also, it works without a problem on Android 2.3.
Checkboxes missing in the 2nd and 3rd setting:
Checkbox visible when touching the row:
Preferences and the code for them is very basic and has nothing custom added.
My xml file with preferences looks like this (only checkboxes copied):
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="show_romaji"
android:title="#string/preferences_romaji_title"
android:summary="#string/preferences_romaji_explanation"
android:defaultValue="true"
android:persistent="true" />
<CheckBoxPreference
android:key="send_statistics"
android:title="#string/preferences_statistics_title"
android:summary="#string/preferences_statistics_explanation"
android:defaultValue="true"
android:persistent="true" />
</PreferenceScreen>
Preferences activity:
public class PreferenceActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SharedPreferenceFragment())
.commit();
}
}
Preferences fragment:
public class SharedPreferenceFragment extends PreferenceFragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
I'm using a theme which has almost nothing defined as well:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.JlptVocabulary" parent="Theme.AppCompat">
<!-- Set AppCompat’s color theming attrs -->
<item name="colorPrimary">#ffe91e63</item>
<item name="colorPrimaryDark">#color/black</item>
<!-- The rest of your attributes -->
<item name="android:windowBackground">#color/backgroundBlack</item>
</style>
</resources>
I'm stuck with this problem and haven't been able to find a solution after doing some research and experiments. Anyone has a clue?

The checkboxes in preferences for Theme.AppCompat style are black (box outline and fill except for the check mark). The check mark takes color of preferences background. In your case, you are setting black background, so checkboxes do not show since they are now all black. I suggest using a separate style (say: Theme.Pref_JlptVocabulary) for the preferences with its normal grayish background so checkboxes appear.
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Pref_JlptVocabulary" parent="Theme.AppCompat">
</style>
</resources>
The other way would be to customize the checkboxes background and check mark colors by redefining the style for checkbox views how-to-customize-the-color-of-the-checkmark-color-in-android....

You can also try using one of the ThemeOverlays
<style name="SettingsTheme" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:windowBackground">#color/backgroundBlack</item>
</style>
I found that this gave suitable checkboxes on a black background. However, on Lollipop devices (values-v21) I still use the regular theme extending Theme.Appcompat since ThemeOverlay seemed to override my 'colorAccent' values on Lollipop phones

I found another solution for the issue.
This may cause because if we set colorControlNormal as same as the application background color in MyMaterialTheme.Base theme in style.xml file.
Solution: Change colorControlNormal other than application default background color.

Related

Unable to start activity ComponentInfo,I have no idea [duplicate]

I am trying to use a custom title to include an image button to the title bar.
I got a lot of help form this post: android: adding button to the title of the app?, but could not get it work for my ListActivity.
In a nutshell, following is what I have:
I hide the titlebar in the AndroidManifest.xml
The specify a relative layout for the custom title (workorder_list_titlebar.xml)
My Activity Class looks like the following:
public class WorkOrderListActivity extends ListActivity {
String[] orders={"WO-12022009", "WO-12302009","WO-02122010", "02152010"};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.workorder_list_titlebar);
setContentView(R.layout.workorder_list);
setListAdapter(new ArrayAdapter(this,R.layout.workorder_list, R.id.label,orders));
}
}
When I ran the app, I got AndroidRuntimeException: You cannot combine custom titles with other title features.
Base on the stack trace, the exception was thrown by com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:183), that was triggered by setlistAdapter call.
Does anyone have the same problem with ListActivity?
Also once I manage to get this work, how do I attach listeners to the image button for it to do something?
Thanks in advance.
I had the same issue and I fix it deleting
<item name="android:windowNoTitle">true</item>
from my theme.xml
Make you create custom style in “values” folder. Make sure you code as below.
<style name="CustomTheme" parent="android:Theme">
Don't modify parent parameter.
This did work for me.
Instead of modifying your theme.xml you may also:
create a new XML style file my_theme.xml in values folder like this:
<style name="MyWindowTitleBackground">
<item name="android:background">#444444</item>
</style>
<style name="MyTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/MyWindowTitleBackground</item>
</style>
You may define other settings as you like in this theme.
Then just use this theme in your manifest within the activity's attributes
android:theme="#style/MyTheme"
Finally set your custom title as always in your activity.java:
final Window window = getWindow();
boolean useTitleFeature = false;
// If the window has a container, then we are not free
// to request window features.
if (window.getContainer() == null) {
useTitleFeature = window
.requestFeature(Window.FEATURE_CUSTOM_TITLE);
}
setContentView(R.layout.screen_main);
if (useTitleFeature) {
window.setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title);
// Set up the custom title
main_title = (TextView) findViewById(R.id.title_left_text);
main_title.setText(R.string.app_name);
main_title = (TextView) findViewById(R.id.title_right_text);
main_title.setText(R.string.Main_titleInfo);
}
Don't forget to define the custom_title.xml file in your layout folder. For example...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical" >
<TextView
android:id="#+id/title_left_text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:ellipsize="end"
android:singleLine="true" />
<TextView
android:id="#+id/title_right_text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:ellipsize="end"
android:singleLine="true"
android:textColor="#fff" />
</RelativeLayout>
I think notenking is right, that this is a problem in activities within tabs. Since some of my activities can either be stand-alone or within a tab, I've found the following helps:
final Window window = getWindow();
boolean useTitleFeature = false;
// If the window has a container, then we are not free
// to request window features.
if(window.getContainer() == null) {
useTitleFeature = window.requestFeature(Window.FEATURE_CUSTOM_TITLE);
}
setContentView(layoutId);
if (useTitleFeature) {
window.setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
}
May be you find this problem when use it in tab,for there already have a title and you can not add a custom title again.
you should add this custom title in the activity which you get the Tab
I did exactly as Sunny Dasari did but with one small change I put the # before and android in the parent attribute.
So my code looked like this.
<style name="CustomTheme" parent="#android:Theme">
To avoid crashing, you can simply add
android:theme="#style/android:Theme"
to the <Activity> tag in your AndroidManifest.xml:
<activity
android:name="test.TestActivity"
android:label="#string/app_name"
android:theme="#style/android:Theme">
This is because the styles defined in your default theme conflict with FEATURE_CUSTOM_TITLE (such as the attribute android:windowNoTitle). By using another theme, you can avoid such problems.
However, you might further need to define your own theme to change other attributes, such as android:windowTitleSize, background color, text color and font, etc. In this case, you can derive your theme from an existing theme (e.g., Theme.Light) and modify its attributes:
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="#style/android:Theme.Light">
<item name="android:windowNoTitle">false</item>
<item name="android:windowTitleSize">60dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
</style>
</resources>
Try swapping following lines:
setContentView(R.layout.workorder_list);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.workorder_list_titlebar);
I have run into this issue as well and it looks like it is an issue with what theme is applied to an activity in the AndroidManifest.xml file. If I use a theme like:
android:theme="#android:style/Theme.Holo
Then it will throw the error
android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
However if I use a different theme like:
android:theme="#android:style/Theme.Black"
then it will not throw the error and subsequently will not crash. However I am trying to use a theme like Theme.Holo. I'm not sure if there is a way around this.
Since, I was trying to compile my program in android 4.0, I was facing the same problem. None of these solutions helped.So, I copied my style contents from values > styles.xml and pasted it in values-v11 styles.xml file and values-v14 styles.xml file. Bingo, the trick worked.
As a beginner most of the answers didn't help me for my case. So here is my answer.
Go to res/values folder in your android project and check for strings.xml (this file may vary in your case, something like themes.xml)
Inside the file under resource tag check whether you have style tags. If you don't find it, add the code below as mentioned below as a child to resources tag
something like below
<resources>
<style name="SomeNameHere">
<item name="android:windowNoTitle">true</item>
</style>
</resources>
if you already have style tag, just add the code below to your style tag
<item name="android:windowNoTitle">true</item>

Android PreferenceFragment title text color

I'm using a AppCompatPreferenceActivity that uses a PreferenceActivity simplified UI for phones (no fragments), but a two-pane UI with PreferenceFragment when it's a tablet.
Until now, I used only a light theme (my theme's parent is Theme.AppCompat.Light) and no problem, it looks like this when in two-pane mode:
I'm now implementing a dark theme, so this time, my theme's parent is "Theme.AppCompat".
And it looks like this:
As you can see, the title of the preference fragment is black on a dark grey background. How can I set this "title" color?
Note: on Pre-Lollipop, it was easy, we would just have to att that to the preference activity theme:
<item name="android:textColorSecondary">#AAAAAA</item>
... but it doesn't work anymore on Lollipop and Marshmallow.
Any idea?
By checking the PreferenceActivity code, I eventually found that the title on the right pane is not part of the preference fragment, but is the fragment "breadcrumb".
By searching for an answer with this keyword ("breadcrumb"), I saw that someone already asked the same thing, and the accepted answer is great and details all about how to do it, and why it's a little more complicated than just changing a color in a style.
Here's the question: Changing the highlight and title color for fragments in PreferenceActivity
And the direct link to the answer: https://stackoverflow.com/a/27078485/1534408
Did you try like this?
in styles.xml
<style name="PreferenceScreen" parent="YourApplicationThemeOrNone">
<item name="android:textColor">#color/TitleColor</item>
</style>
in Manifest
<activity
android:name="MyPreferenceActivity"
...
android:theme="#style/PreferenceScreen" >
</activity>
I changed it by overriding Category theme.
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
//other stuff
<item name="preferenceTheme">#style/MyPrefTheme</item>
</style>
<style name="MyPrefTheme" parent="#style/PreferenceThemeOverlay">
<item name="preferenceCategoryStyle">#style/CategoryStyle</item>
<item name="android:preferenceCategoryStyle">#style/CategoryStyle</item>
</style>
<style name="CategoryStyle" parent="Preference.Category">
<item name="android:layout">#layout/category_view</item>
</style>
layout/category_view.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="#android:id/title"
style="?android:attr/listSeparatorTextViewStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:textColor="#color/white"
android:layout_height="wrap_content"
/>
to know more visit Preference style.xml

Dependent preferences display wrong color font when disabled

In my app I am using several preferences, including some of them related with dependencies using the following attribute: android:dependency="pref_key".
Basically, when the checkbox is not selected, all the other preferences below are disabled:
The problem happens when I setup back the following 3 lines in my custom theme:
<style name="AppThemeOrange" parent="#style/AppTheme">
<item name="android:textColorPrimary">#color/OrangeMain</item>
<item name="android:textColorSecondary">#color/OrangeDark</item>
<item name="android:textColorTertiary">#color/OrangeLight</item>
(...)
The colors defined on these 3 attributes also override the default font color of the disabled preferences:
The preferences are still well disabled, but the fonts displayed make believe the contrary...
I searched in the default Holo Light styles and theme, but I have no idea where this is defined and why the styles above override these ones.
Did anyone already meet the problem?
you should define a color state list and put it inside the /res/color folder
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_enabled="false" android:color="#FF00ff00"/>
<item android:color="#FFff0000"/>
</selector>

Change whole application's text color programmatically

I would like to change the whole application's text and background color in Java, is this possible? With this I mean to change the color of every item in the application (TextViews, ListView items, everything).
Is this possible?
I have tried using a custom-made style but I can't make it work. Here is the xml file (put in the res/layout/values folder):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Light">
<item name="android:textColor">#00FF00</item>
</style>
</resources>
Let's say I just want to change the text color for now.
Now I call this style in my application like this:
public void onCreate(Bundle icicle) {
Activity.setTheme(android.R.style.light);
super.onCreate(icicle);
setContentView(R.layout.main);
But I get the error light cannot be resolved or is not a field.
Update:
One way I found to do this programmatically is to restart the activity, calling
this.setTheme(R.style.Light);
onCreate(null);
However, this works only for the current activity and not for the whole application. It would be great if it were possible to do this launching another activity, not only the current one.
You're trying it in a bit to simple way. Like this you're just adjusting your general Activity's background instead of all the different Views that are out there.
In order to try and adjust every type of View (Button, TextView etc) you'll need to address all their own styles to overwrite them.
Per example if you want to adjust Button you'll need in your own general style:
<item name="android:buttonStyle">#style/ButtonHoloDark</item>
This will point at your own custom style, which takes its parent from the Android's standard Button.
<style name="ButtonHoloDark" parent="android:style/Widget.Button">
<item name="android:background">#drawable/btn_default_holo_dark</item>
<item name="android:textColor">#ffffff</item>
</style>
Be warned, doing this for every View will take you quite some themes and styles.
You can find a great example how to do this exactly in theHoloEverywhere lib, which basically does the same for creating a holo theme backported to Android 2.2 or so
Finally, drop the Activity.setTheme(android.R.style.light); stuff, and just set your own theme via the manifest.
Ok so I found one possible solution, which is to pass the theme information between the activities using intents and the putExtra method.
Code for the first activity (the caller):
Intent i = new Intent(this, ActivityToCall.class);
i.putExtra("key", R.style.Light);
startActivity(i);
Code for the second activity (the called one):
public void onCreate(Bundle icicle) {
int theme = getIntent().getIntExtra("key",-1);
this.setTheme(theme);
super.onCreate(icicle);
// other code...
I don't know if it's the best possible approach but at least it works.
The attributes you want change are:
<style name="AppTheme" parent="android:style/Theme.Holo">
<item name="android:textColorPrimary">...</item>
<item name="android:textColorSecondary">...</item>
</style>
There are a few other ways to change them: Please Refer to this information
You can then set this Theme via the Manifest or setTheme(R.style.AppTheme) in your Activity's onCreate(...)

Can I set ListView and ListFragment selected color in an application-wide theme?

I have an application with two Activities. The first Activity is a ListActivity. The second Activity is a FragmentActivity, with two Fragments in it. The first Fragment is a ListFragment. I'd like to format the application using a custom Theme that extends Theme.Light. I've successfully changed the windowBackground, but when I try to change listSelector nothing happens. Is it possible to do this through a Theme, or do I have to do it separately on each list? Here's my code:
My Custom Theme:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="StitchTheme" parent="android:Theme.Light">
<item name="android:listSelector">#ffffff</item>
</style>
</resources>
Then, in my Manifest, I put:
<application
android:theme="#style/StitchTheme" >
I've also tried doing this by setting up a selector.xml and setting android:listSelector in my Theme, but it has no effect. Thoughts?

Categories

Resources