I'm a beginner in Android development and I trying to build my theme but I have a problem. I tried searching answers on google, d.android but to no avail.
ActionBar is changing color (this is OK), but text and icon of app doesn't show (only if I use my theme - if I use default theme everything is OK). Why?
res/values/styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="AppTheme">
<item name="android:background">HEX COLOR</item>
<item name="android:titleTextStyle">#style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle" parent="AppTheme">
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>
Here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.appname"
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/AppTheme" >
<activity
android:name="com.example.appname.Intro"
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>
"You should add following code in onCreate() method.
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher); "
I see the problem that you use AppTheme as parent for MyActionBar style and it causes circular dependency. MyActionBar -> AppTheme -> MyActionBar ... You should use android:Widget.ActionBar or similar as parent of your action bar theme.
Also there should be android:Theme.Holo.Light instead of android:Theme.Light as parent of AppBaseTheme.
Here is how your res/values/styles.xml file should look like:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Holo.Light"/>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="android:Widget.ActionBar">
<item name="android:background">HEX COLOR</item>
<item name="android:titleTextStyle">#style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle" parent="AppTheme">
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>
Related
I have removed the action bar for a specific activity and it is working perfectly and the action bar is removed when I run the app on Emulator/Device but the problem is that it is still showing in the preview. Due which It affects my design.
Here is my style file where I set the noAction bar:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<!-- Text Styles -->
<style name="textStyle">
<item name="android:textColor">#color/theme_color</item>
<item name="android:textSize">16sp</item>
</style>
<style name="textStyle.tagline">
<item name="android:textAllCaps">true</item>
<item name="android:textSize">46sp</item>
</style>
<!-- Button Styles -->
<style name="button_transparent">
<item name="android:textAllCaps">true</item>
<item name="android:textColor">#color/theme_color</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="button_blue">
<item name="android:textAllCaps">true</item>
<item name="android:textColor">#color/white</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
</resources>
I have also applied that style on activities as shown here:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.eapple.karumber">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Splash_Screen" android:theme="#style/AppTheme.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".protips_activity" android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
</manifest>
But is still showing in the preview as shown here:
Android Studio preview
Fastest solution:
Open your activity's XML.
Switch to the design tab.
On the upper part of the design tab click on AppTheme.
Choose your new theme (the one with no action bar).
However
Adding this line to the activity XML root view should automatically reference to the same activity theme set in AndroidManifest
tools:context=".YourActivityName"
If this is only on the preview u can change the theme with an option on the top of the view. Just select you theme with NoActionBar
Here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.domain.project"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="25"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="com.tns.NativeScriptApplication"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name="com.tns.NativeScriptActivity"
android:label="#string/title_activity_kimera"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="#style/LaunchScreenTheme">
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="#style/AppTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.tns.ErrorReportActivity"/>
</application>
</manifest>
And here is my values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- theme to use FOR launch screen-->
<style name="LaunchScreenThemeBase" parent="Theme.AppCompat.Light.NoActionBar">
<!--<item name="toolbarStyle">#style/NativeScriptToolbarStyle</item>-->
<item name="colorPrimary">#color/ns_primary</item>
<item name="colorPrimaryDark">#color/ns_primaryDark</item>
<item name="colorAccent">#color/ns_accent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/splash_screen</item>
<item name="android:windowActionBarOverlay">false</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
<style name="LaunchScreenTheme" parent="LaunchScreenThemeBase">
</style>
<!-- theme to use AFTER launch screen is loaded-->
<style name="AppThemeBase" parent="Theme.AppCompat.Light.NoActionBar">
<!--<item name="toolbarStyle">#style/NativeScriptToolbarStyle</item>-->
<item name="colorPrimary">#color/ns_primary</item>
<item name="colorPrimaryDark">#color/ns_primaryDark</item>
<item name="colorAccent">#color/ns_accent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="AppTheme" parent="AppThemeBase">
</style>
<!-- theme for actioon-bar
<style name="NativeScriptToolbarStyleBase" parent="Widget.AppCompat.Toolbar">
<item name="android:background">#color/ns_primary</item>
<item name="theme">#style/ThemeOverlay.AppCompat.ActionBar</item>
<item name="popupTheme">#style/ThemeOverlay.AppCompat</item>
</style>
<style name="NativeScriptToolbarStyle" parent="NativeScriptToolbarStyleBase">
</style> -->
</resources>
I can change values in android:windowFullscreen and the app goes fullscreen or not, accordingly to the boolean set. So, I know that the manifest file is being parsed correctly. However, the title bar / action bar / toolbar is simply never hiding and always appears with the app in the title.
I am using this angular seed, not sure if relevant: https://github.com/TeamMaestro/angular-native-seed
I've been stuck in this for some time now, can someone help? Thanks :)
I can change values in android:windowFullscreen and the app goes
fullscreen or not, accordingly to the boolean set. So, I know that the
manifest file is being parsed correctly. However, the title bar /
action bar / toolbar is simply never hiding and always appears with
the app in the title.
Your manifest is correct, but your preview is set up wrong. You have to remember that the Android Studio preview doesn't reflect how your application will actually look when run on a real device.
I created a dummy project to explain. Here is code that removes the action bar, similar to what you have:
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
Which looks like this in source code:
<style name="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Now this clearly tells the app to not show an action bar, just like your theme does. However, if you look at the preview, you will see this:
So then how do you make your preview accurately reflect your theme? Well, click here:
And adjust your theme to include no action bar!
As a result, you have no action bar in the preview and in the application:
Let me know if this was helpful!
i Go Through Your Code and havent found any Problem ,But Maybe There is issue with code but U can Try Compare with This style that works for me:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Add this code to style.xml
<style name="AppTheme.NoActionBar.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and add this code to AndroidManifest.xml
<activity
android:name="com.tns.NativeScriptActivity"
android:label="#string/title_activity_kimera"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="#style/AppTheme.NoActionBar.NoActionBar">
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="#style/AppTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.tns.ErrorReportActivity"
android:theme="#style/AppTheme.NoActionBar.NoActionBar"/>
Try this in your styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<!-- Customize your theme here. -->
I updated my SDK API 20 to API 22 in Eclipse.
After Updating My Sdk i Imported My Project from Other Workspace
Problem:
Actionbar App icon Not Showing in My Application.
I Already set theme Color in Themes.xml thats not Showing. it Changed as Default Black Colour.
Its Changed full structure of my App. Before Updating it works fine.
Please anyone Help me to Solve this.
manifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/CustomActionBarTheme" >
<activity
android:name="com.example.Start"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabStyle">#style/MyActionBarTabs</item>
<!-- Support library compatibility -->
<item name="android:actionBarTabTextStyle">#style/MyTheme.ActionBar.TabText</item>
<item name="android:actionBarTabBarStyle">#style/Divider</item>
</style>
<!-- for Tab divider -->
<style name="Divider" parent="#android:style/Widget.Holo.ActionBar.TabBar">
<item name="android:divider">#android:color/transparent</item> //or use your transparent drawable image
<item name="android:showDividers">middle</item>
<item name="android:dividerPadding">0dp</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/easy</item>
<!-- Support library compatibility -->
<item name="background">#color/easy</item>
</style>
<style name="MyActionBarTabs" parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#drawable/actionbar_tab_indicator</item>
</style>
<style name="MyTheme.ActionBar.TabText" parent="android:style/Widget.Holo.ActionBar.TabText">
<!-- This is a Black text color when selected and a WHITE color otherwise -->
<item name="android:textColor">#color/selector_tab_text</item>
</style>
</resources>
I had the same problem.
To show icon use:
getSupportActionBar().setIcon(R.drawable.ic_your_icon);
in your activity onCreate()
And for color add:
<item name="colorPrimary">#color/your_color</item>
to "CustomActionBarTheme" (not to "MyActionBar"!)
And your theme should look like:
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabStyle">#style/MyActionBarTabs</item>
<item name="colorPrimary">#color/your_color</item><!--put your color here-->
<!-- Support library compatibility -->
<item name="android:actionBarTabTextStyle">#style/MyTheme.ActionBar.TabText</item>
<item name="android:actionBarTabBarStyle">#style/Divider</item>
</style>
And the other stuff in your theme.xml stays unchanged
How does one style the Android ActionBar overflow menu (background color, text color, custom drawables etc.)?
I've been trying to do this with the following styles, but nothing seems to be taking any effect. Any help would be greatly appreciated.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarWidgetTheme">#style/MyActionBar</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:textColor">#android:color/holo_blue_light</item>
<item name="android:actionBarItemBackground">#android:color/holo_green_light</item>
<item name="android:actionMenuTextColor">#android:color/holo_green_dark</item>
</style>
</resources>
TIA!
BTW minSdk set to 14
AndroidManifest is
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app1.app1">
<application android:allowBackup="true"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Do you call it on AndroidManifest.xml file?
Example in my style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/green_dark</item>
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/white</item>
<item name="android:textStyle">bold</item>
</style>
and in menifestfile
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher1"
android:label="#string/app_name"
android:theme="#style/CustomActionBarTheme" >
<activity.....
For implement click listener, you need create option menu for this case.
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