I've been trying to customize my Toolbar using the support library. while setting android:theme works perfectly on API21+ , lower APIs seem to completely ignore it.
here's my xml:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" makes the toolbar have White icons in API21+, the icons remain black on older devices.
update: I tested by adding another child (tabLayout) to my appBarLayout. the theme was correctly applied. however the support toolbar completely refuses to recognize the theme even if set directly.
After days of struggling I finally found the problem. my layout was set before calling super.onCreate() and for whatever reason this made Toolbar not apply proper theme in pre-lolipop devices where the native Toolbar is not used.
so I made sure:
setContentView(R.layout.main);
comes after:
super.onCreate(savedinstancestate);
hey your have to make the styles files with the version number .
For that go to the values and right click and then click the Values Resource file
then name the file as styles and then in the dialog under the option available Qualifiers select the version file then press the icon >> and then enter the version 19 on it and this file will work for a version less then Api 21+
this is the dialog you will get on click of value Resource file
this is the final dialog where you need to enter your version number
It might help you.
You have set the theme style in API version based folders and apply, So that it will apply based on the API versions.
put themes inside styles.xml.
then replicate the styles.xml in values folder for different API levels based folder[based on your requirement you have to create value-X folders]
please refer below image.
Click here to view image
Related
I made a navigation icon through the Vector Asset wizard in Android Studio to place in my Toolbar. By default, the color of the image is black. It doesn't give me the option to change it in the wizard. So is there a way to change the color in xml? This is how it is set in my toolbar layout file:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
app:navigationIcon="#drawable/nav_menu_icon">
</android.support.v7.widget.Toolbar>
As you can see, the image is set as app:navigationIcon="#drawable/nav_menu_icon". So is it possible to change the icon's color? I tried this solution but it wasn't working for me. The other solutions were given in code but I would like to use an xml version if possible. Also, my app is supporting API 16 and later.
You can change color of "nav_menu_icon".
Need to open nav_menu_icon.xml in studio or any editors and change the attribute "fillColor".
It's android:fillColor="#FF000000" by default.
I added for about 8 Months ago a ActionBar in my App.
Now that I've read that the Toolbar has more functionality I thought to add the Toolbar as ActionBar.
I've added this:
<android.support.v7.widget.Toolbar
android:id="#+id/listview_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/kevox"
android:elevation="4dp"
android:theme="#style/MyActionBar" />
on android:elevation="4dp" I get the Message that this function is ignored in minSdkVersion=17.
That's how a Button is placed in Toolbar.
As you can see, the MenuItem like the Button does not fill the whole Toolbar.
Is it a good Idea to use a Toolbar in this SDK Version? As I saw in the statistics API 17-19 is still the most used Android-Version.
Creating an activity with navigation drawer in Android Studio causes this to be shown in the XML code:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
If I remove the tools:openDrawer="start", on the layout preview, the navigation drawer will be closed instead of open.
I thought this was a replacement attribute, similar to android:text that can be replaced with tools:text to put some placeholder text in the layout preview. But when I change it to android:openDrawer or app:openDrawer, the app can't be compiled because they are unknown attributes.
So I wonder how tools:openDrawer works, and whether it is documented anywhere.
Android has a dedicated XML namespace intended for tools to be able to
record information in XML files, and have that information stripped
when the application is packaged such that there is no runtime or
download size penalty. The namespace URI is
http://schemas.android.com/tools and is usually bound to the tools:
prefix:
This means that tools attribute is used by the IDE and not used in the code functionality.
I am still trying to find the complete documentation of all tools attributes. I can't find out the openDrawer attribute anywhere. But the following are great documentation on tools:
http://tools.android.com/tech-docs/tools-attributes
http://tools.android.com/tips/layout-designtime-attributes
UPDATE
Now a complete documentation of all tools attribute is available here.
It makes the navigation drawer visible on the preview screen in Android Studio essentially mimicking the user swiping the drawer onto the screen.
Without this attribute, you would see only the content view of the main screen.
I haven't tried it but I suspect substituting "start" for "end" would make the drawer on the right of the screen open (assuming there is one of course).
Even though there's no subtitle in my Toolbar, the title is shifted to top. How can I align it with navigation icon?
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:navigationIcon="#drawable/abc_ic_ab_back_mtrl_am_alpha"
android:gravity="top"
app:title="Hello title"
android:background="#drawable/citylook"/>
You should assing a minHeight to your Toolbar.
<android.support.v7.widget.Toolbar
android:minHeight="?attr/actionBarSize">
I faced a similar issue recently and managed to find the solution. I hope that'll fix yours too. I just paste the link here 'cause I'm lazy: Android Toolbar: title and overflow menus aligment issue on 5.0 only
Basically, if you are launching the application on a Lollipop device, there is no need to set an Activity with no ActionBar and replace it with a Toolbar: you have to code different themes and layouts for pre-Lollipop and Lollipop devices.
Let me now if that works for you as well!
I have different activities in my project with listview in it. I am using app compact v7 and following material design.My requirement is to shown transparent toolbar and statusbar like iOS and when user will scroll the listeview towards up. listview should be visible behind the toolbar and actionbar. Please let me know how can i do this. I tried a lot of solution but could not achieve the desired o/p.
Styles
<item name="colorPrimaryDark">#android:color/transparent</item>
XML Layout
<android.support.v7.widget.Toolbar
android:id="#+id/my_awesome_toolbarAdd"
android:layout_height="56dp"
android:layout_width="match_parent"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="#android:color/transparent" />
You can try this (don't do the optional step #5 in your case):
Unable to make toolbar transparent in Android