After applying custom theme Action bar dosen't show up - android

I have an application using action bar
styles.xml
<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="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>
<color name="custom_theme_color">#ffa900</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">#color/custom_theme_color</item>
<item name="android:colorBackground">#color/custom_theme_color</item>
</style>
</resources>
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbar"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme" >
<activity
android:name="com.example.actionbar.ActionBarActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
My Question is that initially by default it was using Theme.Light and action bar is displayed but when I have customized a theme using parent as Theme.Light it dosen't work but if I use parent as Theme.Holo then it works for custom theme. Anyone any Idea.

Here is what I have done. It is working perfectly for me. In Res->value->style
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomTheme"
parent="#style/Theme.Light">
<item android:name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style android:name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item android:name="background">#drawable/actionbar_background</item>
</style>
</resources>
Then in drawable folder(create one if you don't have it),create a new xml actionbar_background and paste the below code in it.
<?xml version="1.0" encoding="utf-8"?>
<bitmap android:tileMode="repeat"
android:src="#drawable/ab_texture_tile_example"
xmlns:android="http://schemas.android.com/apk/res/android"/>
Then you place your custom colour in the other drawable folders. Here ab_texture_title_example is my background colour used.

Related

Actionbar does not show up in devices, but in emulator does

I have been developing an app and I was using an emulator as tester. When the app was finished I tested it in an Android 5 and also 4 but the Actionbar just won't show up. The platform of the emulator is 5.1.1 as the first phone where I tested it. The only thing that came into my mind is the manifest file that could contain something wrong, here it is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.flexenergy.swapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/myActionBarTheme" >
<activity
android:name="com.flexenergy.swapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Another thing, I have a drawable listview menu on the left that should appear by pressing on the actionbar (which is not shown) but it does come up if I slide a finger from left to right.
The only styles.xml is the following (and I place it in values-v22, values-v11, etc):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--theme applied to the application or activity-->
<style name="myActionbarTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">#color/lightBlue</item>
</style>
<!-- actionBar styles -->
<style name="MyActionBar" parent="android:Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- actionBar title text -->
<style name="MyActionBarTitleText" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/lightBlue</item>
<item name="android:textSize">20sp</item>
</style>
<!-- actionBar tabs text styles -->
<style name="MyActionBarTabText" parent="android:Widget.Holo.ActionBar.TabText">
<item name="android:textColor">#color/lightBlue</item>
</style>
<!--
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="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>
</resources>

Android Custom ActionBar Style

I'm trying to make a custom theme for my android app. But the problem is that I can't change actionbar theme. When the style is applied, it gave me the following error and shutdown the app:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I can't understand what I'm doing wrong. Here's my code:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.liderlink.dev.acelink" >
<application
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AcelinkTheme">
<activity
android:name=".Dashboard"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
res/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light">
<!-- Customize your theme here. -->
</style>
</resources>
res/values/themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="AcelinkTheme"
parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/AcelinkActionBar</item>
</style>
<!-- colors -->
<color name="aceblue">#438eb9</color>
<!-- ActionBar styles -->
<style name="AcelinkActionBar"
parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/aceblue</item>
</style>
</resources>
The exception is pretty clear : you need to use a theme that inherits from Theme.AppCompat, probably because you are using ActionBarActivity, which requires it as specified in the docs.
You can do this :
<style name="AcelinkTheme" parent="#android:style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/AcelinkActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="AcelinkActionBar" parent="#android:style/Widget.AppCompat.ActionBar">
<item name="android:background">#color/aceblue</item>
</style>
For clarity, it is better to have colors defined in their own resource file IMHO.
According to this thread, you should change your parent to a Theme.AppCompat theme derivate:
<style name="AcelinkTheme"
parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/AcelinkActionBar</item>
</style>
This link should also help you to customize your theme: Styling the Action Bar :)

How to change the Action bar tab text color

I need to change the Action bar tab text color.So far Action bar tab text color displayed in black.But I need to change it into white color.
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fth.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<application
android:name="com.sit.fth.app.GemsApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Light" >
<activity
android:name="com.sit.fth.activity.SplashActivity"
android:launchMode="singleTask"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</activity>
</application>
</manifest>
res/values/styles.xml:
<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="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>
<style name="GridLayout">
<item name="android:drawSelectorOnTop">true</item>
<item name="android:listSelector">#drawable/photogrid_list_selector</item>
</style>
<style name="CustomRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/custom_ratingbar</item>
<item name="android:minHeight">20dip</item>
<item name="android:maxHeight">20dip</item>
</style>
<style name="CustomTheme" parent="#android:style/Theme">
<item name="android:tabWidgetStyle">#style/CustomTabWidget</item>
</style>
<style name="CustomTabWidget" parent="#android:style/Widget.TabWidget">
<item name="android:textAppearance">#style/CustomTabWidgetText</item>
</style>
<style name="CustomTabWidgetText"
parent="#android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">12sp</item>
<!-- <item name="android:textStyle">bold</item> -->
</style>
</resources>
In res/color.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="list_bg_normal">#00000f</drawable>
<drawable name="list_bg_normal_audio">#ededed</drawable>
<drawable name="list_bg_pressed_audio">#FFFFFF</drawable>
<drawable name="list_bg_pressed">#848484</drawable>
<color name="grid_state_pressed">#BB7dbcd3</color>
<color name="grid_state_focused">#777dbcd3</color>
<drawable name="app_theme_bg">#F5F5FA</drawable>
<color name="title_detail_color">#000000</color>
<color name="duration_color">#e4e4e4</color>
<color name="content_color">#454545</color>
</resources>
Anybody can help me with these.Thank you.
Declare this in your AppTheme:
<item name="android:actionBarTabTextStyle">#style/tabtextcolor</item>
Then here is the style declaration:
<style name="tabtextcolor" parent="#android:style/Widget.Holo.Light.ActionBar.TabText">
<item name="android:textColor">#android:color/white</item>
</style>
Use this in our theme to set the actionbar text color:
<item name="titleTextStyle">#style/ActionBar.CustomTitle</item>
<!-- ActionBar title text -->
<style name="ActionBar.CustomTitle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/title_detail_color</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
Sorry, this is for the case you are using AppCompat support library.
You could use the general:
<!-- ActionBar title text -->
<style name="ActionBar.CustomTitle"
parent="#style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/title_detail_color</item>
</style>
Also, instead of Holo, you could try some other themes that match your current theme.
You can also read more on the official documentation:
https://developer.android.com/training/basics/actionbar/styling.html

Android: Custom Action Bar Theme Error - (No Resource Found that Matches . . .)

I am working with Android in Eclipse.
So I'm trying to implement a custom theme, and I keep getting this error from my manifest file:
error: Error: No resource found that matches the given name (at 'theme' with value
'#android:style/CustomActionBarTheme').
Ideas? Thanks!
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/CustomActionBarTheme" >
<activity
android:name="com.example.myfirstapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- A child of the main activity -->
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
</manifest>
Themes.xml (Custom theme)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
</style>
<!-- ActionBar Styles -->
<style name="MyActionBar"
parent="android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
<!-- ActionBar tabs text styles -->
<style name="MyActionBarTabText"
parent="#android:style/Widget.Holo.ActionBar.TabText">
<item name="android:textColor">#color/actionbar_text</item>
</style>
</resources>
Styles.xml
<resources>
<!--
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="#android:Theme.Holo.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>
</resources>
You're referencing the system's resources when you use #android:.... Instead use #style/CustomActionBarTheme.
You need to use
android:theme="#style/CustomActionBarTheme
You are referring to the style in your themes.xml.
There is not resource with the name #android:style/CustomActionBarTheme

Defining theme in Android APP

I have tried to add in Manifest
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
and in style
<resources>
<!--
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="android:style/Theme.Holo.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>
</resources>
No matter what I do i always have black action-bar and nothing changes... I want to apply Holo Light theme ...
Any suggestion?
create a custom theme.
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>
manifest.xml
<application
...
android:theme="#style/MyAppTheme">
</application>
OR
Create Custom Action Bar
actionbar_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/ActionBarCompat" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dip"
android:paddingTop="15dip"
android:scaleType="center"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold"
android:text="NAME" />
</LinearLayout>
In your layout file. main_activity.xml
<include layout="#layout/actionbar_layout"/>
in values->styles.xml
<style name="ActionBarCompat">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">50dp</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">#drawable/actionbar_background</item>
</style>
If you want to use the theme in your whole app, try this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Light" >

Categories

Resources