I am developing sample application using android studio. In that application I am using action bar and I need to put an image below the action bar. I tried but the line is showing the between action bar and image.
I achieved this
but i need like this
how to accomplish this task.
please help me.
Thanks
Naresh
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="required height"
android:fitsSystemWindows="true">
<ImageView/>
</android.support.design.widget.AppBarLayout>
try out this xml structure for your design and let me know if you got any problem in it
In order to remove the shadow add this to your app theme:
<style name="MyAppTheme" parent="android:Theme.Holo.Light">
<item name="android:windowContentOverlay">#null</item>
</style>
Maybe you can use a Linear Layout with horizontal orientation as a Fake ActionBar and put the three lines imageAsset, the actionBarLogo and the actionBarTittle, and apply a Hidden ActionBar style, and when the three lines button is clicked, just call the threeLinesBtn.performClick() idk is just an opinion.
Related
How do I remove the boundary between action and toolbar?
Bad Case
Good Case, I want to like it.
Activity XML
Fragment XML
What you are looking for is a way to remove the shadow under toolbar.
For android 4.4 or below, you will have to set the window content overlay in your activity theme like this
<style name="Theme.MyApp" parent="Theme.AppCompat.Light.NoActionBar">
...
<!--To hide shadow effect in toolbar for Android 4.4 or below-->
<item name="android:windowContentOverlay">#null</item>
</style>
For Android 5.0+, you will also need to set the toolbar elevation to 0 in the activity layout like this.
<LinearLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
...
>
<android.support.design.widget.AppBarLayout
...
app:elevation="0dp">
...
</android.support.design.widget.AppBarLayout>
</LinearLayout>
Actually, many people ask about this. See answer here
Try to search for existing answer next time ;)
I' developing an android app and I need to use my custom title bar using a picture and two buttons. The thing is, immediately when I launch my app, during 1 or 2 seconds before my custom title bar appears, there is the ugly default one with "my application" displayed. The minimum targeted API is 15.
All the answers found on stack overflow didn't work, or succeed to make it disappear but was doing the same to my custom title bar.
Here is how I call it from my activity:
supportRequestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
super.onCreate(savedInstanceState);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.topbarclassic);
Since my first view is a fragment I dont call SetContentView
And this is my custom styles.xml:
<resources>
<style name="theme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowNoTitle">false</item>
</style>
</resources>
Once again my custom title bar works properly. I just need to get rid of the default one displayed quickly when the app starts. Thanks a lot!
if you use this style the activity will load without an action bar
<style name="theme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Then you should really be using a toolbar to set the action bar. For example :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize" />
</RelativeLayout>
Then in your activity you can set the action bar like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(...);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
Dont forget to set your them in your AndroidManifest.xml
<activity
android:name=".path.MyActivity"
android:theme="#style/theme"/>
If found a workaround for my problem using Modge's link about splashscreen.
It doesn't solve the problem itself but remains a good workaround.
I created a small activity in charge of the splash screen, avoiding the white first screen to stay for too long. Then this splash redirect on my main activity.
This is also useful in my case since I can start some connection process during the splash screen. You can follow this example: http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/
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>
I've created a separate xml style file targeting KitKat and I've managed to change the color of the status bar. The only side-effect as seen on the picture, all the content is now moved up beneath the status bar. My question is how can I change the color of the status bar without overlaying this or how can I know the exact top margin I need to put on my content so its starts after the ActionBar and not beneath. Of course I need this to behave as expected on all screen sizes and densities. Thank you
values-v19/styles.xml
<style name="ThemeSelector" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
You should add the following to the top of the view(s)
android:paddingTop="?android:attr/actionBarSize"
If you're using the Support Library for the action bar, you need to remove the android: prefix
android:paddingTop="?attr/actionBarSize"
By enabling translucent system bars, your layout will fill the area behind the system bars, so you must also enable fitsSystemWindows for the portion of your layout that should not be covered by the system bars.
EDITED
You can add
android:fitsSystemWindows="true"
in your XML File
Remove from your layout
android:fitsSystemWindows="true"
I am using actionbar sherlock and it works very well. The only problem I have is to figure out how to set the background image for the area which is used by the activities. All I end up with is setting a background image for the actionbar itself.
Any suggestion highly appreciated
martin
The windowBackground attribute is perfect for this.
<style name="MyTheme" parent="Theme.Sherlock">
<item name="android:windowBackground">here!</item>
</style>
Just set the background for your main layout in your activity.
Eg. in your layout file:
<LinearLayout 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:orientation="vertical"
android:background="#drawable/myImage" >
just write following line of code in your onCreate().
getSupportActionBar().setIcon(R.drawable.your_image);