Should I use Toolbar on minSdkVersion 17 in Android? - android

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.

Related

Is it possible to have tabs without a toolbar when developing an app for Android with material design?

I am new to android development and I want to make an app that is almost immersive. Does android let you remove the toolbar and use only the tabs?
Yes, android.support.v7.widget.Toolbar is optional. You can remove it anytime from your layout.
If you don't want to use Toolbar then just use TabLayout in your layout XML:
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="#ff4938"/>
Hope this will help~

Android:Theme has no effect on older Apis

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

Relative Layout is not allowed inside Toolbar

I'm facing strange warning, trying to customize the Toolbar appearance. I put RelativeLayout inside android.support.v7.widget.Toolbar to reorganize Toolbar. Everything works and appears as expected on both emulator and device. The only problem is the annoying warning that appears in .xml file as seen below:
The question is what is the actual problem, how can it harm my application and how can I solve this warning. As I know Toolbar behaves as ViewGroup, why RelativeLayout is not allowed to be it's child?
Thanks.
Toolbar extends from ViewGroup and RelativeLayout's too.
I've tried that on Android Studio 1.5.1 and i couldn't see that problem.
<android.support.v7.widget.Toolbar
android:id="#+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:id="#+id/toolBarTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textSize="18dp">
</RelativeLayout>
</android.support.v7.widget.Toolbar>
You should be able to update your Android Studio to the last version or checking if you are using outdated Platform, then you need to just update that Platform to the last version.
And then it won't show up.or perhaps it will fixed in the next update.

Android toolbar Alignment issue

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!

Transparent toolbar and statusbar

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

Categories

Resources