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

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>

Related

react-native android: How to change the color of ListView "end of scroll" animation?

How can I change the color of the animation?
The color is based on your accentColor in your AppTheme.
To change it, change your AppTheme (generally in res/values/styles.xml) to:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">#F00</item> <-- change to color
<!-- Status Bar color -->
<item name="colorPrimaryDark">#000</item>
<!-- Details color -->
<item name="colorAccent">#000</item>
</style>
Beware it's an global app change, every scrollview bounce animation will have this color.
To change only the overflow animation color, use android:colorEdgeEffect. Otherwise it will be inherited from the colorPrimary in AppTheme.
The accepted answer should be changed to specify colorPrimary instead of colorAccent.
See answer here: android lollipop scrollview edge effect color
Put this inside android/app/src/res/values/styles.xml
<item name="android:colorEdgeEffect">#E53644</item>
if someone is using expo managed app, it's not supported by expo yet, but there's a workaround.
you'd need to expo eject -> to transition to bare workflow. then as said above within android/app/src/res/values/styles.xml add
<item name="android:colorEdgeEffect">#E53644</item>.
now the worst part which took me hours to figure out - you'll have 2 themes generated by default the AppTheme and Theme.App.SplashScreen, it didn't work until I've added it to splashscreen one :/. I've added it to both themes just in case. note that this specific change will work only when you run android specific native build npm run android, for more please read this
I'm using Expo managed workflow + react native paper with Material UI v3 and in debugging the color of the "ripple" was purple.
But luckily, when I test it over the Google Play Store, it was based on the primary color (or primary container color).
PS: I had similar issues with the color of dialog buttons and the app icon being not shown correctly.

Navigation drawer toggle padding

I'm using appcompat v7 with the hamburger to arrow toggle.
However, I would like to add some padding on the left of the toggle.
This is my current situation :
http://nl.tinypic.com/r/2a0f712/8
This is what I would like to have :
http://nl.tinypic.com/r/v3q176/8
I've tried this :
findViewById(android.R.id.home).setPadding(25, 0, 15, 0);
But that didn't work. However, this did add padding on the right of the toggle.
I've also tried to add padding in the styles but that didn't work either.
AFAIK, the action is hard-coded in layout resources. U cant change the padding. Google did this to maintain the consistency across the app guess.
However u can define ur own icon in a drawable with ur own attributes (padding and all) and use it as an indicator by adding this line to styles.xml
<item name="android:homeAsUpIndicator">#drawable/xyz</item>
And the image u have shown about what u want is actually a toolbar and not an action bar. In toolbar, the icon is by default placed there.
To know more about toolbar and how to implement them, here is a link : http://android-developers.blogspot.in/2014/10/appcompat-v21-material-design-for-pre.html
I'm going to assume you are familiar with styling to some extent and recommend you go that route. FYI I have not confirmed the code below as working but I think it would be close to what you want.
For res/values-14/style.xml, something like this:
<!-- style for Action Bar -->
<style name="MyPaddedActionBar" parent="android:style/Widget.Holo.Light.ActionBarView">
<item name="android:paddingLeft">32dp</item>
<item name="android:paddingRight">32dp</item>
</style>
And then for everything 14 and below, you would use AppCompat (res/values-14/style.xml):
<style name="MyPaddedActionBar" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:paddingLeft">32dp</item>
<item name="android:paddingRight">32dp</item>
</style>

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..!!

How to change the accent color on my Android app from blue to something else

All I want to do is change the accent color of my android app, but I'm having a tough time figuring out how to do that. The default for android is blue now, but I want to make it orange.
By accent color, I mean the accent of navigation tabs, the color that highlights when you hit lists, the accent color in pop up dialogs, etc.
I'm using actionbarsherlock if that matters.
Here is an image. I'd like to change the color of that blue accent throughout the app:
It's been some time since you asked this question but now that google has released a new AppCompat version you can do what you want to achieve quite simply. The answer I'm giving you is inspired from android developer blog support library 2.2.1.
Add the support library to your project (I am assuming you are using Android Studio).
For that add these lines to the app.graddle file (assuming your module is named app).
dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
}
Set the theme of your application
These lines are to be added to your styles.xml file. As you can see there are a few items in this style. If you want to know what element they correspond to go check customize android status bar with material.
colorAccent is the color you want to change in the first place.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primaryDark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:textColorPrimary">#color/textColorPrimary</item>
<item name="android:windowBackground">#color/windowBackground</item>
<item name="android:navigationBarColor">#color/navigationBarColor</item>
</style>
You will also need to set your application theme in the Android manifest
<application
android:theme="#style/AppTheme" >
...
</application>
Change From Activity / ActionBarActivity to AppCompatActivity in your classes.
public class MainActivity extends AppCompatActivity
{
....
}
You will probably need to change some methods due to the AppCompatActivity. Look at the video in the first link to better understand that :)
Change your widgets to the AppCompat ones
<LineareLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatTextView
android:id="#+id/text"
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.v7.widget.AppCompatButton
android:id="#+id/btn_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_start" />
</RelativeLayout>
Et voilĂ  ! That's it you're all set :) You can now change the Accent color easily.
You're going to want to use state layout lists.
http://developer.android.com/reference/android/content/res/ColorStateList.html
You might need to make one of these for each of the widgets that is going to have a new default selected color.

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