ActionBar logo is not displaying in XXHDPI mobile device - android

I am working with action bar and i want to customize the action bar logo. For that i have written code (below) but its working for Samsung and MicroMax devices but not for Lenovo K900 and Sony Ericssion Xperia z1. What should i do?
Api 16 its working fine but not in 17 (4.2)
Code:
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:logo">#drawable/product_category_logo</item>
<item name="android:background">#drawable/actionbar_theme</item>
<item name="android:backgroundStacked">#color/black</item>
<item name="android:backgroundSplit">#color/white</item>
<item name="android:textColor">#000000</item>
<item name="android:textSize">16sp</item>
</style>
Values-v14 Folder:
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
Values-v11 Folder:
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<!-- <style name="AppBaseTheme" parent="android:Theme.Holo.Light"> -->
<style name="AppBaseTheme" parent="android:Theme.Light"><!-- Recent changes -->
<!-- API 11 theme customizations can go here. -->
</style>
Guy i don't know what should i do. Please help me out.

I would suggest you to use ActionBarSherlock project in your application. Because this project already handles this kind of things for you.
And just for the sake of verification, Google is also using this ActionBar in its Google I/O app.
You can also download this project from GitHub ActionBarSherlock which also includes demo versions of this open source project.
To add ActionBarSherlock to your project:
Simply git clone the repo from GitHub in your workspace. And then import it as -> create project from existing source in Eclipse.
After this go to Project->Properties->Android and Add it as Library.
Here is your answer for importing it: Importing Actionbarsherlock into eclipse
And after importing it look for the Sample projects in it, how they are making use of Sherlock Action Bar. You will get a lot of info from there.
Most important thing about ActionBarSherlock is that you can also use it for Android OS below 3.0 but official Android API provide Action Bar widget only above OS v3.0. So you can target your app for all kind of users, those who are using OS above 3.0 and below 3.0, both will be targeted.

Please add below theme in all folder - values,vaules-11values-14
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:logo">#drawable/product_category_logo</item>
<item name="android:background">#drawable/actionbar_theme</item>
<item name="android:backgroundStacked">#color/black</item>
<item name="android:backgroundSplit">#color/white</item>
<item name="android:textColor">#000000</item>
<item name="android:textSize">16sp</item>
</style>
i think you have to use actionbarsharelock or actionbarcompart for < android 3.0
but first put this theme in values-11,values-14 and test the app.
also use theme MyActionBar in android manifest file.
try and let me k'no

Related

Material Design support below Lollipop - crashes

I've been trying to implement the Material Design theme, following these instructions.
I'm not using ToolBar (must I?)
ALL my Activities extends ActionBarActivity.
Using getSupportActionBar() all across the project.
I'm compiling and targeting to API 21 in gradle (minimun is API 15).
My <application> tag contains android:theme="#style/AppTheme"
Running the application on Lollipop device (with a specific v21 similar theme works).
My styles.xml:
<style name="AppBaseTheme" parent="#style/Theme.AppCompat">
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="displayOptions">useLogo|showHome</item>
<item name="logo">#drawable/home_page_logo</item>
<item name="background">#color/actionbar_background_color</item>
<item name="textColor">#color/white</item>
<item name="titleTextStyle">#style/MyActionBarTextStyle</item>
</style>
No matter what I tried, the application crashes the second I launch my main activity on onCreate() with this crash log:
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
Did anyone experience this issue? any suggestions on what might cause this?
Edit:
It's definitely something in my styles.xml theme. If I force the app to use the default Theme.AppCompat theme, it works.
What might cause a theme to fail? I verified the ActionBar attributes are not using "android:". Anything else?
SOLVED...
2 of my jar libs apparently have generated values.xml that contains styles of both AppTheme and AppBaseTheme.
I verified only our dependencies modules, as jar libraries shouldn't declare application themes, specially not with the name of the default ones.
Before posting the answer, I added to my AndroidManifest.xml <application>
tools:replace="android:theme" and declared the new theme, assuming it'll work and my application will override any other theme.
The solution eventually, stupid as it is, was to rename my own AppTheme and AppBaseTheme to different names and now it works.
Hours spent on such a trivial fix. Hopefully, this will spare some time for others.
parent should be Theme.AppCompat not #style/Theme.AppCompat.
Using #style/ you'll be using the style from the Android API 21, and it must be the style from the AppCompat library.
edit:
probably same thing for the Widget.AppCompat
edit2:
like this
<style name="AppBaseTheme" parent="Theme.AppCompat">
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="displayOptions">useLogo|showHome</item>
<item name="logo">#drawable/home_page_logo</item>
<item name="background">#color/actionbar_background_color</item>
<item name="textColor">#color/white</item>
<item name="titleTextStyle">#style/MyActionBarTextStyle</item>
</style>
Try remove the "#style/" from the first line in the styles.xml so you have:
<style name="AppBaseTheme" parent="Theme.AppCompat">

Android 5.0 is not supporting for lower versions

Please help me.
I got struck in solving this error for more than 3 days
I didnot get the proper solution.
I have updated my eclipse to run android 5.0.
I had created a simple android application using minimum version 16 and target version 21 to run android 5.0 material theme.
Have added the theme in styles.xml as like this
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">#color/accent</item>
</style>
</resources>
I followed the link to add supporting libraries appcompatv7.
http://developer.android.com/tools/support-library/features.html#v7
But I am getting error stating that R cannot be resolved to variable
whenever I add this appcompat to my project.
please give me a suggestions and also please share your android 5.0 running in lower version project.
for api lower than 21 use Theme.AppCompat instead of android:Theme.Material
please read here http://developer.android.com/training/material/compatibility.html
Your theme.xml should be something like this.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/grey_main</item>
<item name="colorPrimaryDark">#color/grey_main</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
</resources>
check your mainactivity.java.
your r.java file could have not generated so that you might get error mentioning R cannot be Resolved
Must add Add appcompat into your project library
sdk\extras\android\compatibility\v7\appcompat
Add AppBaseTheme
<style name="AppBaseTheme" parent="Theme.AppCompat">
read compatibility for material theme and add appcompat into your project as library that you can find in
sdk\extras\android\compatibility\v7\appcompat
than
your style.xml
<style name="AppBaseTheme" parent="Theme.AppCompat">

Android: defining action bar style for a device running KitKat

I am defining action bar styles for an Android device running 4.4.2. I've tested the styles on a device running 4.3 and they work prefectly. The phone running KitKat however refuses to apply any of the rules defined by the style. I've defined the same theme in all three folders: values, values-11 and values-14.
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:actionBarStyle">#style/MyStyledActionBar</item>
</style>
<style name="MyStyledActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:background">#drawable/oc_actionbar_background</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<item name="android:actionMenuTextAppearance">#style/MyActionBarMenuText</item>
<item name="android:actionMenuTextColor">#style/MyActionBarMenuText</item>
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverFlow</item>
<item name="android:displayOptions">showHome</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#696969</item>
</style>
<style name="MyActionBarMenuText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textColor">#696969</item>
</style>
<style name="MyActionButtonOverFlow" parent="#style/Widget.AppCompat.Light.Base.ActionButton.Overflow">
<item name="android:src">#drawable/ic_action_search</item>
</style>
I've also added
android:theme="#style/AppTheme"
to the manifest application tag. But the styles are still not applied. I have however managed to change the action bar properties at runtime (changing the color), but that's not a desirable way of handling such problems.
If anyone could advise me on the matter, I would be most grateful.
To prevent these kind of issues, I like to use the following tool to generate the style for me: http://jgilfelt.github.io/android-actionbarstylegenerator/
Easy to use tool that generates the style just like I want it. Might help you too, since you avoid these issues. Just paste this in your project, and you're done.
Other tools can be found here: http://romannurik.github.io/AndroidAssetStudio/index.html

android:windowActionBarOverlay & android:actionBarStyle requires api level 11

I am making an android app and using android-support-v7-appcompat to make sure my app support action bars from android version 2.2 and up.
I need to make the Action Bar overlay and use a translucent background so I have modified the styles.xml to this code :
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<!-- TRANSLUCENT THEME -->
<style name="TranslucentAB" parent="Theme.AppCompat.Light">
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionBarStyle">#style/BlackBar</item>
<item name="actionBarStyle">#style/BlackBar</item>
</style>
<!-- TRANSLLUCENT COLOR STYLE -->
<style name="BlackBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/halfblack</item>
<item name="background">#drawable/halfblack</item>
</style>
</resources>
and modified manifest file to adapt the new ActionBar as :
android:theme="#style/TranslucentAB"
The problem is that the following two lines of code require API level 11 and up :
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionBarStyle">#style/BlackBar</item>
but I need to support from API level 8 and up. If I remove these two lines the app runs fine on Android 2.2 with black translucent action bar. But if I run the app in Android 4.3 the app launches with a solid white action bar. halfblack is just a png file in drawable folder with 70% black color.
Found solution to my problem :
I have to make separate styles.xml in res/values-v11 to support the same functionality in android 3.0 and up
To use the action bar overlay with the support library, do this:
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
Notice how the style name does not include the android: prefix.

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8?

Have researched this to death and just cannot find the answer.
I have an ActionBar using AppCompat. I am supporting up to API v7 (API v8 would do). ActionBar works perfectly from API v11. API < v11 has the problem of removing an icon (and thus a feature) from the ActionBar without supplying an Overflow. The big picture is that I have an App Logo, an App Title, and 3 Icons all squidging into the same ActionBar on a low end phone. Trying to make some room!
I would be happy with 1 of 2 solutions. Either:
A method of getting an Overflow so that the functionality can be retrieved from a pull down.
(Preferred) A method of removing the icon and text from ActionBar
Below is my current XML for API 11+:
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/LiteActionBarStyle</item>
<item name="actionBarStyle">#style/LiteActionBarStyle</item>
</style>
<style name="LiteActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:displayOptions"></item>
</style>
</resources>
Specifically:
<item name="android:displayOptions"></item>
This iss the attribute that is unavailable before API v11.
This is where I am so far:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/LiteActionBarStyle</item>
</style>
<style name="LiteActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"></style>
</resources>
What is the alternative for APIs prior to v11?
EDIT:
Updated Style with transparency suggestion:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/LiteActionBarStyle</item>
</style>
<style name="LiteActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:icon">#android:color/transparent</item>
</style>
</resources>
Solved it!
When working with API < v11, you have to remove the "android:" element of the attribute in Style. For example:
<style name="LiteActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="displayOptions"></item>
</style>
This is how it should look in Styles with API >= v11
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/LiteActionBarStyle</item>
<item name="actionBarStyle">#style/LiteActionBarStyle</item>
</style>
<style name="LiteActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:displayOptions"></item>
</style>
Also, I was missing some Icons when I applied this on device with API < v11. I had to change the Icons to Always display:
<item
android:id="#+id/actionInvertShake"
MyApp:showAsAction="always"
android:contentDescription="#string/shakeChangeContentDescription"
android:icon="#drawable/shake"
android:title="#string/shakeOption"/>
Note that the Namespace is "MyApp" rather than "android"
This removes the Title and Icon of App from ActionBar and displays all icons from Right to Left.
Set <item name="android:icon">#android:color/transparent</item>
It will not take up any space in the ActionBar.

Categories

Resources