My code is as below and while it works ( when I change the parent Theme to Theme.Sherlock or Theme.Sherlock.Light the Theme it does changes) it does not changes the Title color.
The code is pretty much the same as here
Code :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="#style/Theme.Sherlock">
<item name="actionBarStyle">#style/MyTheme.ActionBarStyle</item>
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="#style/Widget.Sherlock.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#style/TextAppearance.Sherlock.Widget.ActionBar.Title" >
<item name="android:textColor">#FF0000</item>
</style>
</resources>
i have changed title color like this
actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>ActionBarTitle </font>"));
From Jake Wharton's ActionBarSherlock site :
Mirrored Attributes
Due to limitations in Android's theming system any theme
customizations must be declared in two attributes. The normal
android-prefixed attributes apply the theme to the native action bar
and the unprefixed attributes are for the custom implementation.
Had to change MyTheme.ActionBarStyle to :
<style name="MyTheme.ActionBarStyle" parent="#style/Widget.Sherlock.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
Now the Title text color has changed.
Use below code to provide different color to actionbar text and actionbar background just use below theme in manifest against the activity in which you want output :)
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/TitleBarTextColor</item>
<item name="android:background">YOUR_COLOR_CODE</item>
</style>
<style name="TitleBarTextColor" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">YOUR_COLOR_CODE</item>
</style>
Simplest way that worked for me is to add the following in theme style:
<item name="android:textColorPrimary">#color/orange_dark</item>
I tried all the above methods, it does n't worked for me.I have just achieved through code below..
Spannable text = new SpannableString(actionBar.getTitle());
text.setSpan(new ForegroundColorSpan(Color.BLUE), 0, text.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
actionBar.setTitle(text);
If you are trying to change the title text where you have a custom toolbar then try adding app:titleTextColor to the toolbar as below:
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="#color/colorWhite" />
in your style.xml in values folder this will change your action bar color.. Replace #666666 with your selected color code for title background color and replace #000000 for your title text color.
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/NewActionBar</item>
</style>
<style name="NewActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/TitleBarTextColor</item>
<item name="android:background">#666666</item>
</style>
<style name="TitleBarTextColor" parent="#style/TextAppearance.Sherlock.Widget.ActionBar.Menu">
<item name="android:textColor">#000000</item>
</style>
then dont forget to edit your manifest file -> android:theme="#style/NewTheme"
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/NewTheme" >
<activity
android:name="com.nearby.welcome.Splash"
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>
Related
In my activity, I use default ActionBar
<style name="AppTheme" parent="Theme.AppCompat"> and getSupportActionBar()
How can I custom the style of this ActionBar?
Change ActionBar color and title color
Align title to center
Add more top padding to ActionBar
For the color, I tried these two style, but it also change color of whole Activity, I just want to change ActionBar
<item name="colorPrimary"></item>
<item name="android:textColorPrimary"></item>
I alo tried actionBarStyle, but it is not working
<style name="AppTheme" parent="Theme.AppCompat">
<item name="colorPrimary">#color/darkgray</item>
<item name="colorPrimaryDark">#color/black</item>
<item name="colorAccent">#color/gold</item>
<item name="android:textColorPrimary">#color/gold</item>
<item name="android:textColorSecondary">#color/darkgray</item>
<item name="android:windowBackground">#color/black</item>
<item name="android:colorBackground">#color/black</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/gray</item>
<item name="android:textColor">#color/black</item>
</style>
I suggest you to include the Toolbar in your layout and use the Theme.AppCompat.NoActionBar theme for your Activity :
Layout :
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/yourColor">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#color/yourColor"
android:text="yourTitle" />
</android.support.v7.widget.Toolbar>
Manifest :
<activity
android:name="yourActivity"
android:theme="#style/Theme.AppCompat.NoActionBar" />
I'm struggling to override the default themes app bar color properly.
When I use the android:actionBarStyle it changes the color but then the title text is missing.
<resources>
<style name="ToolbarThemeStyle" parent="android:Theme.Material.Light">
<item name="android:actionBarStyle">#style/ActionBarTitle.Background</item>
</style>
<style name="ActionBarTitle.Background" parent="">
<item name="android:background">#8DC44E</item>
<item name="android:titleTextStyle">#style/ActionBarTitle.Text</item>
</style>
<style name="ActionBarTitle.Text" parent="">
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>
I've tried Replacing the Action Bar but I'm wondering if there's not a shorter and easier way.
Manifest:
<application android:label="Home Automation" android:icon="#mipmap/ic_launcher" android:theme="#android:style/Theme.Material.Light"
</application>
Activity:
[Activity(Label = "Label", MainLauncher = false, Theme = "#style/ToolbarThemeStyle", NoHistory =true)]
Thanks all for your replies. I thought I'd answer this myself whereas I've spent hours trying to figure this out.
The obvious solution was in this page under Using Custom Themes but I was getting the error "No resource found that matches the given name (android:color Primary)". Changing android:minSDKVersion=23 also did not work.
I went to Application Properties and set the "Compile using Android version" to the current targeting framework (i.e. API 23) instead of the maximum which was not installed yet set to API 25.
make sure are you setting theme to activity in menifest or xml. Here I am sharing my theme code you can refer.
<style name="MaterialAppTheme" parent="Theme.AppCompat.Light">
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/red</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
This code should be in you style.xml
<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>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
And make sure you should have declared it in manifest.xml
<application
android:name=".app.AppController"
android:allowBackup="true"
android:icon="#drawable/images"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
Hello I am using the Sherlock library to achieve the ActionBarTabs in Android but there is some weird issue that text appear in the Tabs are all caps. I dont want to make all caps to captital. How can I achive this ?
I tried this but this is not working
values-v14.xml
<style name="TariffPlansTheme" parent="Theme.Sherlock">
<item name="actionMenuTextAppearance">#style/MyMenuTextAppearance</item>
<item name="android:actionMenuTextAppearance">#style/MyMenuTextAppearance</item>
</style>
<style name="MyMenuTextAppearance" parent="TextAppearance.Sherlock.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
</style>
AndroidManifest.xml
<activity
android:name="TariffPlansActivity"
android:label="#string/title_activity_tariff_plans"
android:screenOrientation="portrait"
android:theme="#style/TariffPlansTheme">
</activity>
Thanks in advance.
This solved my issue. I was using wrong parent style Menu instead of Tab
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light" />
<style name="TariffPlansTheme" parent="Theme.Sherlock">
<item name="actionBarTabTextStyle">#style/My.TabText.Style</item>
<item name="android:actionBarTabTextStyle">#style/My.TabText.Style</item>
</style>
<style name="My.TabText.Style" parent="#style/Widget.Sherlock.ActionBar.TabText">
<item name="android:textAllCaps">false</item>
</style>
</resources>
In my styles.xml file I have a style to remove the title bar and other styles to change my tabwidget's font size:
<?xml version="1.0" encoding="utf-8"?>
<style name="RemoveTitleBar" parent="android:Theme">
<item name="android:style/Theme.Black.NoTitleBar.Fullscreen">true</item>
<item name="android:windowNoTitle">true</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>
In my AndroidManifest.xml file I set the RemoveTitleBar style to the application which works fine:
<application
android:icon="#drawable/ic_launcher_test_icon"
android:label="#string/app_name"
android:theme="#style/RemoveTitleBar"
....
However when I apply the CustomTheme style to my activity with tabs, I get the title bar back. But if I remove the line it works fine.
<activity android:name=".TabActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/CustomTheme"> </activity>
Am I going about this the wrong way or do I have to change something in my styles.xml file? Thanks for you time.
You are extending CustomTheme with "android:style/Theme":
<style name="CustomTheme" parent="android:style/Theme">
<item name="android:tabWidgetStyle">#style/CustomTabWidget</item>
</style>
and the titleBar is available in in this you aren't removing the titleBar, you will again need to remove the titleBar like this:
<style name="CustomTheme" parent="android:style/Theme">
<item name="android:tabWidgetStyle">#style/CustomTabWidget</item>
<item name="android:style/Theme.Black.NoTitleBar.Fullscreen">true</item>
</style>
<activity android:name=".activity.MyHomePage" android:theme="#style/AppTheme.Light" android:label="New Tasks"/>
I have that Activity in my AndroidManifest.xml file. How do I set style on that android:label. I would like to set textsize and textcolor.
<style name="AppTheme.Light" parent="#android:style/Theme.Holo.Light">
<item name="android:windowBackground">#drawable/background</item>
<item name="android:actionBarStyle">#style/ActionBarTextSize</item>
<item name="android:windowTitleSize">14pt</item>
</style>
OR
<style name="ActionBarTextSize" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:textSize">14pt</item>
</style>
Are you talking about creating a custom window title style? If so, check this out: http://www.londatiga.net/it/how-to-create-custom-window-title-in-android/