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

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>

Related

Android theme changes do not change reliably

I am trying to learn how to edit custom app themes in Android.
But for some reason changes in my styles.xml (manually and with theme editor) are being reflected on my device in an unreliable sporadic way. The behavior is perplexing.
Like I did 50 build , cleans, rebuild, etc last night trying to get option menu items text to change color and it wouldn't. Then today it just changed...and I dont know why.
I try to change the main background color, and it wouldn't change. Then all of a sudden after a build the optionmenu background color changed to the color I set main background color to.
I have not found anything reliable or reproducible in this problem.
Theme changes just are not working for me and when they do it is sporadically.
I have disabled instant run, and uninstalled app, as well as cleaned , rebuild, and made project. None of those actions have any effect on whether theme changes will take hold.
My v11, v14, and v21 styles.xml are empty, and I only modify the main styles.xml.
styles.xml
<resources>
<style name="AppBaseTheme" parent="android:Theme.Material">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<item name="android:colorBackground">#color/black</item>
<item name="android:colorForeground">#color/common_signin_btn_dark_text_pressed</item>
<item name="android:textColorPrimary">#color/text_color_primary</item>
<item name="android:textColorSecondary">#color/text_color_secondary</item>
<item name="android:textColorSecondaryInverse">#color/text_color_inverse</item>
<item name="android:textColor">#color/text_color_primary</item>
<item name="android:itemTextAppearance">#style/MenuItemTextAppearance</item>
<item name="android:dialogTheme">#style/DialogTheme</item>
</style>
<style name="MenuItemTextAppearance">
<item name="android:textColor">#000000</item>
</style>
<style name="DialogTheme" parent="android:Theme.Material.Dialog.Alert">
<item name="android:colorBackground">#color/background</item>
</style>
androidmanifest
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.me.myapp"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:name=".LocalApp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppBaseTheme">
<activity
android:name=".ActMain"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".ActExport"
android:label="#string/title_activity_export"
android:windowSoftInputMode="stateAlwaysVisible">
</activity>
<!--
ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information.
-->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<activity
android:name=".ActSaveFile"
android:label="#string/title_activity_act_save_file">
</activity>
<activity
android:name=".ActLoadFile"
android:label="#string/title_activity_act_load_file">
</activity>
</application>
</manifest>
Your style AppBasteTheme which extends from android:Theme.Material is supported only above 21 sdk level your min sdk level is 15 which is small.Instead of this use this style which works fine.
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<item name="android:colorBackground">#color/black</item>
<item name="android:colorForeground">#color/common_signin_btn_dark_text_pressed</item>
<item name="android:textColorPrimary">#color/text_color_primary</item>
<item name="android:textColorSecondary">#color/text_color_secondary</item>
<item name="android:textColorSecondaryInverse">#color/text_color_inverse</item>
<item name="android:textColor">#color/text_color_primary</item>
<item name="android:itemTextAppearance">#style/MenuItemTextAppearance</item>
<item name="android:dialogTheme">#style/DialogTheme</item>
You have to write like this you missed additional styles.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

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

Cant set Android Actionbar Background correctly

The Problem
When im setting the ActionBar Background Color the Bar looks like this:
i cant upload Images here so here is the File:
Android ActionBar Problem
My values/styles File
<?xml version="1.0" encoding="utf-8"?>
<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">
<!--
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">
<item name="actionBarStyle">#style/ActionBarTheme</item>
</style>
<!-- Action Bar theme -->
<style name="ActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#drawable/actionbar</item>
<item name="background">#drawable/actionbar</item>
</style>
<style name="FullscreenTheme" parent="android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">#style/ButtonBar</item>
<item name="metaButtonBarButtonStyle">#style/ButtonBarButton</item>
</style>
<style name="ButtonBar">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingRight">2dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:background">#android:drawable/bottom_bar</item>
</style>
<style name="ButtonBarButton" />
</resources>
My Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.application"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/symbol"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.application.Main"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.application.Settings"
android:parentActivityName="com.application.Main"
android:screenOrientation="portrait"
android:theme="#style/ActionBarTheme">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.application.Main" />
</activity>
<activity
android:name="com.application.DateList"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="#style/FullscreenTheme" >
</activity>
</application>
</manifest>
I also try this but the same happened
ColorDrawable draw = new ColorDrawable(R.color.grey);
getSupportActionBar().setBackgroundDrawable(draw);
My Color Drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#color/grey" />
</shape>
getSupportActionBar().setBackgroundDrawable(draw);
should be, in your case
getSupportActionBar().setBackgroundDrawable(getResources.getDrawable(R.drawable.your_drawable_name);
The Constructor of ColorDrawable takes the int that represent the color, not the id of the color. Use instenad
ColorDrawable draw = new ColorDrawable(getResources().getColor(R.color.grey));
Edit:
about the style.xml, you need both the item with and without the android prefix:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/ActionBarTheme</item>
<item name="actionBarStyle">#style/ActionBarTheme</item>
</style>
Lint is probably going to complain about it, because of the minSDK value. if it does you can add tools:ignore="NewApi" to the item with the android: prefix. For instance:
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/ActionBarTheme</item>

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

After applying custom theme Action bar dosen't show up

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.

Categories

Resources