Change only background and color of titlebar - android

I am trying to customize background and color of Title bar. I have seen many example on android site and stack overflow but nothing worked out for me.
In examples they are adding new elements in title bar but i want to customize existing title bar.
I do not want to change anything else. I only want to change background color and font color of text.

If you are using Android Lollipop (api 21+), you can edit the "styles21.xml" (in the res directory) code and add the following:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material">
<!-- Customize your theme using Material Design here. -->
<!-- Title Bar color here -->
<item name="android:colorPrimary">#YOUR_COLOR_HERE</item>
<!-- Background color here -->
<item name="android:windowBackground">#YOUR_COLOR_HERE</item>
</style>
</resources>
For more information see Google's "Using the Material Theme" here.
This XML code will work throughout the whole app (each different view) unless otherwise specified.
I hope this is what you are looking for!

Related

How to customize the "up" button when the searchView is being expanded?

Background
My app has the ability to search for items (which are other apps) using the SearchView on the ActionBar.
The app uses the support library of Google, and it works well on all versions of Android from API 9 .
The problem
On Lollipop, when I click the search action item in order to start searching, I notice that the up/back button on the top-left corner gets to be white, which is bad for this case since the actionbar background is also quite white:
Weird thing is that it doesn't always occur, and I don't think it occurs on Android versions that aren't Lollipop (tested on multiple emulators and devices).
Another weird thing is that the navigation drawer icon seems ok, as well as the X icon inside the searchView.
Here's the XML of the toolbar I have:
<android.support.v7.widget.Toolbar
android:id="#+id/activity_app_list__toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />
the "colorPrimary" is set to be : #ffEFEFEF .
Also, the theme's parent of the activity is "Theme.AppCompat.Light.NoActionBar" , as I've set the toolbar to be the actionBar.
The question
How can I fix this issue?
What is the cause for this issue? How come it works fine on other Android versions?
It seems like a known issue: https://code.google.com/p/android/issues/detail?id=78346 .
workaround is here: https://code.google.com/p/android/issues/detail?id=78346#c5 , meaning:
values-21/themes.xml:
<style name="MyTheme" parent="Theme.AppCompat">
<item name="homeAsUpIndicator">#drawable/abc_ic_ab_back_mtrl_am_alpha</item>
</style>
That's it. Hope it gets fixed later.
In order to customize it, I assume I can use it, and also choose the color using "colorControlNormal"
I'd guess the "app:collapseIcon" attribute is what you were looking for?
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbarHeight"
app:collapseIcon="#drawable/collapseBackIcon" />
How can I fix this issue?
I created a utility class for this (and other) problems. Get it here:
https://gist.github.com/consp1racy/96958a1dedf5a99d4ca5
Part 1: Call the following method in your Activity.onCreate(Bundle):
ToolbarUtils.fixToolbar(mToolbar);
Part 2: The code uses value android:colorControlNormal from the Toolbar "theme" you specified in the layout. If you use support library and defined only colorControlNormal you need to add the following line after it:
<item name="android:colorControlNormal" tools:ignore="NewApi">?attr/colorControlNormal</item>
What is the cause of this issue?
After a lot of thought and experiments it seems that the arrow uses the original bitmap, which is white, without any coloring, which is wrong.
Note: The menu overflow icon also reads the android:colorControlNormal so now it will display correct color as well.
EDIT: Prerequisites:
Your Toolbar should have attributes similar to the following
<!-- custom toolbar theme -->
<item name="theme">#style/ThemeOverlay.MyApp.ActionBar</item>
<!-- light popup menu theme, change this if you need to -->
<item name="popupTheme">#style/ThemeOverlay.AppCompat.Light</item>
<!-- app bar background color -->
<item name="android:background">#color/material_deep_orange_500</item>
Then the toolbar theme should look something like this
<!-- example uses dark app bar template, feel free to change it to light if you need to -->
<style name="ThemeOverlay.MyApp.ActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- this line defines title text color -->
<item name="android:textColorPrimary">#color/material_white_100</item>
<!-- this line defines subtitle text color -->
<item name="android:textColorSecondary">#color/material_white_70</item>
<!-- this line defines up/hamburger/overflow icons color -->
<item name="colorControlNormal">#color/material_black_54</item>
<!-- this line is necessary for proper coloring on lollipop - do not delete it -->
<item name="android:colorControlNormal" tools:ignore="NewApi">?attr/colorControlNormal</item>
</style>

Material design inverse spinner/edittext theme using AppCompat

I'm having issues creating a Material Design app with the AppCompat v21 theme. First I have my app theme using the AppCompat light with dark actionbar.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/theme_color</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/theme_color_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#color/theme_color_accent</item>
</style>
The color branding for my app is quite dark which is why I use the DarkActionBar variant. My problem is that I have a couple layouts where I'd like to put a Spinner and an EditText inside a layout where the background is my theme_color which is dark. This results in a Spinner/EditText with black color on a dark background. How can I make the style/theme of these controls use the Dark variant so they show up with white text instead of black text. Even worse than that, I need the spinner to show white text but dropdown items of the spinner to show the light version.
I'm using a Spinner inside a Toolbar with dark background and remembered that the Google I/O Android App does the same, so I looked at its styles - more specifically, the ActionBarThemeOverlay here.
After I used the below attributes on my theme, my Spinner background color (the "arrow") changed:
<item name="colorControlNormal">#fff</item>
<item name="colorControlHighlight">#3fff</item>
colorControlHighlight is the color when the user presses the Spinner. I didn't test on an EditText, though.
So, you're looking for a way to apply a different theme to select views.
There's no xml-only way to do that for most elements (except Toolbar, which you already know)
You'll have to inflate the views manually, using a ContextThemeWrapper:
ContextThemeWrapper wrapper = new ContextThemeWrapper(getActivity(),
R.style.Theme_AppCompat); // The dark one
LayoutInflater footPump = LayoutInflater.from(getActivity()).cloneInContext(wrapper);
// Note null as second argument -- if you pass in parent view, theme will
// be taken from the parent
Spinner spinner = (Spinner) footPump.inflate(R.layout.spinner, null);
to have the layout resource for the inflater, just create a single-view xml file:
<!-- res/layout/spinner.xml -->
<?xml version="1.0" encoding="utf-8"?>
<Spinner xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
How about this..
make a style for you widget, ex:
<style name="CustomEditText" parent="android:Widget.EditText">
<item name="android:textColor">#color/red</item>
</style>
then in your xml add this attribute to your EditText
style="#style/CustomEditText"

Modifying the default window title in Android for a tablet?

I am looking for a way to slightly modify the default window title in an Android app for both phone and tablet. The example below is a tablet view of the title bar as standard:
I have tried implementing a custom title bar, which works but the context menu (circled in red) disappears, which I need. All I want to do is change the color of the bottom border or remove the bottom border altogether.
Is there a way to make changes whilst keeping the context menu?
Thanks
In your manifest in application tag define as :
android:theme="#style/mytheme"
Now in res/values you can define a file say theme.xml with content as :
<resources>
<style name="mytheme" parent="#android:style/Theme" >
<item name="android:_DEFAULT_BASE_COLOR_1">#XXXXXX</item>
<item name="android:windowNoTitle">true</item>
... .
</style>
</resources>
This will change the basic colour scheme of your application. Here are the color themes primarily used on Android: http://developer.android.com/design/style/color.html

Actionbarsherlock with Viewpagerindicator

I have an app that is using Viewpagerindicator. I am using the tabs portion of it. I use a black background and the default blue indicator color. I wanted to add an actionbar to my app so I started using Actionbarsherlock. In order to get my tabs to show an the action bar to show I created my own them which is called in my manifest file. The theme I created is this:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is our main ActionBarSherlock theme -->
<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
</style>
<style name="Theme.VPI" parent="Theme.Styled">
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
</style>
</resources>
When I run the app, I get my blue indicator color but the background of the entire app is white.
Originally I was how this code inside:
<style name="Theme.VPI" parent="Theme.Styled">
<item name="vpiTabPageIndicatorStyle">#style/CustomTabPageIndicator</item>
</style>
That gave me red indicators with a white background. I know the custom tabs are red with a white background and that is why I changed it from CustomTabPageIndicator to Widget.TabPageIndicator. However, I am still getting an all white background.
I have tried to just make my layout have a black background inside of my pageviewer, however when I do that, my buttons become really dark and unreadable.
My main question is to find where I can change the color inside of the Viewpagerindicator theme.
Any suggestions would be much appreciated. Thank You.
Visit this example; Making ActionBarSherlock and ViewPagerIndicator play nice
Possible Bug in that example; Android - SupportMapFragment with GoogleMaps API 2.0 giving IllegalArgumentException
Good Luck..!!

styling ActionbarSherlock: textColor of the action-items

I was changing the background of the Actionbar in my App and to make text readable again I have to change the color of the text. I was successful with title/subtitle and the tab-texts, but I am struggling with the text of the action-items - they stay white no matter what I tried . Anyone has a hint on how to do that?
Also the overflow-icon is white which does not look too good on the wooden background - is that an extremely good reason to use the stuff below? I am not really sure what's the reason to not do it, but as I do not have a big device-test-park I better want to be sure ;-)
<!-- the following can be used to style the overflow menu button
only do this if you have an *extremely* good reason to!! -->
<!--<style name="MyOverflowButton" parent="Widget.Sherlock.ActionButton.Overflow">
<item name="android:src">#drawable/ic_menu_view</item>
<item name="android:background">#drawable/action_button_background</item>
</style>-->
I also struggled with this, but the solution to changing action item text color was:
<style name="My.Theme" parent="Theme.Sherlock.Light">
<item name="android:actionMenuTextColor">#android:color/white</item>
</style>
The key here was to use this attribute in the general theme, not in the actionbar style.
Try starting with android:theme="#style/Theme.Sherlock.Light" in your Manifest and then changing your styles. The light theme features dark action items. Or just look through the light theme to find out how to change them.

Categories

Resources