Android - No ripple effect & no tooltip on menu items in toolbar - android

I have a little problem: the "Tooltip" which is showing on long press on a menu item doesn't come up anymore, neither does the ripple effect on the toolbar menu items. Still, the ripple effect is coming on buttons I got in my layout, but not in the toolbar.
I'm not declaring a theme or style for the toolbar, but I'm often changing its color during runtime (but not directly in onCreate, so this should not matter, because it's also not working without changing colors).
Other solutions like this one did not work out for me...
XML for the toolbar:
<android.support.v7.widget.Toolbar
android:background="#color/Grey"
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:elevation="4sp"
android:layout_alignParentStart="true" />
Code for Toolbar:
myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
Inflating menu:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.toolbarmenu, menu);
invalidateOptionsMenu();
return true;
}
My theme is a child from AppCOmpatDark (the NoActionBar one) and in onPrepareOptionsMenu I'm often changing the visibility of the menu items & changing their color...
Any help, also just directions what could trigger this error, is very appreciated.
Thanks for the help!

Even I faced similar issue due to AppTheme. I was using Theme.MaterialComponents.NoActionBar as default theme for App and only for toolbar the ripple effect was not working. However I solved it using app:theme.
Please try adding a app:theme="#style/Theme.AppCompat.Light.NoActionBar" to your toolbar. This is test with androidx.appcompat.widget.Toolbar it is working for me.
<androidx.appcompat.widget.Toolbar
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:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/white"
app:layout_collapseMode="pin"
android:elevation="4dp"
app:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:stateListAnimator="#animator/appbar_elevation"
tools:targetApi="lollipop">
Now all you have to do is add android:background="?attr/selectableItemBackground" to your view to get that ripple/touch effect.
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="?attr/selectableItemBackground"
android:contentDescription="#null"
android:src="#mipmap/ic_launcher" />

I believe I had a similar issue when changing the background colour of certain rows in my application. I figured out that the Ripple Effect on selecting an item was drawing below the background due to changing the colour from the default.
In my ListView, I added XML attribute android:drawSelectorOnTop="true", which brought the Ripple Effect to the Foreground.
Adding this same attribute to your code may fix your issue.
Android Documentation

Related

Can I have "adjustResize" soft keyboard behavior and a toolbar behind the status bar at the same time?

In my Android app, it is vital for me to use the adjustResize behavior for the soft keyboard. So users can scroll down to other UI elements, such as a "continue" button.
I've noticed that that adjustResize only works when I have both the Manifest setting and android:fitsSystemWindows="true" in the layout root element. (Please correct me if I'm wrong!)
But with android:fitsSystemWindows="true" the Toolbar no longer sits behind the Status Bar. Which makes perfect sense, but isn't what I want.
When the Toolbar sits behind it, the status bar has a matching darker shade of my Toolbar's color. What I have with android:fitsSystemWindows="true" is a colorless status bar and a toolbar that sits 24dp lower than I want it.
I will give up the matching colored Status Bar for the sake of the adjustResize keyboard behavior. But my question is, is it possible to have both? Dare I dream for both Beauty and Accessibility?
Anyone more experienced know the magical combination of settings?
Or perhaps, as a work around, a way to explicitly color the status bar?
fyi:
These are Activities with RelativeLayout root elements, and there are ListViews and EditTexts in some of them.
Toolbar is android.support.v7.widget.Toolbar
Potentially relevant Style items:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowContentOverlay">#null</item>
PS - I've read dozens of similar-ish questions on soft keyboard behavior, but was unable to find anything helpful on unintended effects to the Toolbar. Also vice versa, lots of Style questions about toolbar/statusbar behavior, but nothing seemingly relevant. Never the less, sorry if I missed something!
Many thanks in advance!
Edit
I've been playing with removing android:fitsSystemWindows="true" and adding more ScrollViews or trying to get everything into the same ScrollView. This does nothing.
If I remove android:fitsSystemWindows="true" then the bottom of the UI is "glued" to the bottom of the screen -- it does not "resize" to instead glue to the top of the soft keyboard like I would expect it to do with adjustResize set in the Manifest.
Setting android:fitsSystemWindows="true" in the root view makes the UI resize like I would expect -- but it also makes the toolbar no longer draw behind the statusBar.
So I am still exactly where I started :(
Adding a layout XML code sample:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- CoordinatorLayout because this view uses SnackBars -->
<!-- Relative Layout to lock "continue" button bar to bottom -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Main content, that scrolls with or without keyboard -->
<!-- Correctly sits behind transparent Status Bar -->
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/footer_persistent_height">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- ACTUAL VIEWS DELETED FOR BREVITY / CLARITY -->
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<!-- Bottom nav bar -->
<!-- Correctly sits at bottom of UI when keyboard is not visible -->
<!-- PROBLEM: Not accessible when soft keyboard is visible -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
style="?android:attr/buttonBarStyle">
<Button
android:id="#+id/skip_button"
android:theme="#style/ButtonContinueGrey"
android:onClick="skipClickHandler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".5"
style="?android:attr/buttonBarButtonStyle"/>
<Button
android:id="#+id/button_progress"
android:theme="#style/ButtonContinueColored"
android:onClick="continueClickHandler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".5"
style="?android:attr/buttonBarButtonStyle"/>
</LinearLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
I have found a solution that seems to work well with the OS. First set fitSystemWindows = true to the view you want to be reacting to the window and then tell it to ignore the top padding:
ViewCompat.setOnApplyWindowInsetsListener(yourView, (view, insets) ->
ViewCompat.onApplyWindowInsets(yourView,
insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft(), 0,
insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()))
);
Read more here: https://medium.com/google-developers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec
I think you can try to use "adjustPan" instead of "adjustResize" when android:fitsSystemWindows="false". It works for me.
Try to keep your layout in scroll view and remove android:fitsSystemWindows="true" and use only adjust resize
I didn't got your question properly but as far I can understand to solve the problem-
For the padding problem try adding
android:fitsSystemWindows="true"
android:clipToPadding=”false”
And for the transparent status bar add
<item name="android:statusBarColor">#android:color/transparent</item>
to your AppTheme.
Hope it helps rest please upload the screenshot of your problem for detailed problem view.
(Answering my own question)
This does seem to be a bug in android:
https://code.google.com/p/android/issues/detail?id=63777
Posts on the above bug report link to a few suggested work arounds, like creating a custom Layout class or custom Soft Keyboard.
I feel like I've already wasted enough time with this. So my solution is to just manually color the Status Bar.
Solution:
Set android:fitsSystemWindows="true" in either the Layout's root view or globally in style.xml. This (along with adjustResize in the manifest) makes the UI shrink above the Soft Keyboard so no UI is blocked -- the most important thing.
Color the Status Bar. This is only possible in Lollypop and newer. Which is the same as the transparent StatusBar, anyway.
private void updateStatusBarColor(){
// Check Version
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// OPTIONAL: Calculate a darker version of the toolbar color
int color = calculateDarkerColor(toolBarColor);
// Get the statusBar
Window window = getWindow();
// You can't color a transparent statusbar
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// Set the color
window.setStatusBarColor(color);
}
}
// Calculate a darker version of a given color
// Note I do this because the color always changes, if it's always the same I would save the darker version as a Resource in colors.xml
private int calculateDarkerColor(int color){
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] *= 0.8f; // smaller = darker
return Color.HSVToColor(hsv);
}
Its working for me.
In manifest.xml, put this in <activity> tag.
android:windowSoftInputMode="adjustResize"
In your layout's parent tag, put this.
android:fitsSystemWindows="true"
android:clipToPadding="false"
In styles.xml, put this.
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
I have done this with minSdkVersion 16 and targetSdkVersion 26
Here's what worked for me in order to have both a transparent status bar AND working adjustResize keyboard behavior.
First of all, I suggest you watch this 27-minute droidcon talk by Chris Banes, it can be enlightening: https://www.youtube.com/watch?v=_mGDMVRO3iE
In the layout add fitsSystemWindows on the correct level, so that the background image spreads under the status bar. Now fitsSystemWindows will fix the keyboard-layout behavior related to adjustResize.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- EditText etc here -->
In the Activity:
makeStatusBarTransparent(this);
setContentView(R.layout.activity_login);
The extension method:
fun Activity.makeStatusBarTransparent() {
window.apply {
clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
decorView.systemUiVisibility += View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// or:
// decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
statusBarColor = Color.TRANSPARENT
}
}
In the activity tag in the manifest:
android:windowSoftInputMode="adjustResize|stateHidden"
I've decided to do ".systemUiVisibility += ..." so I can set some things like windowLightStatusBar on the theme through xml (I override it in different flavors). But you can specify the LIGHT_STATUS_BAR flag directly (or not, depending on your background).
Keep in mind that fitsSystemWindows overrides padding, so you need to use another layout if you use padding.
I have fix your issue, and also tested at my end. Please change your relative layout to framelayout like this:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- CoordinatorLayout because this view uses SnackBars -->
<!-- Relative Layout to lock "continue" button bar to bottom -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- Main content, that scrolls with or without keyboard -->
<!-- Correctly sits behind transparent Status Bar -->
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="24dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- ACTUAL VIEWS DELETED FOR BREVITY / CLARITY -->
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<!-- Bottom nav bar -->
<!-- Correctly sits at bottom of UI when keyboard is not visible -->
<!-- PROBLEM: Not accessible when soft keyboard is visible -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
style="?android:attr/buttonBarStyle"
android:layout_gravity="bottom">
<Button
android:id="#+id/skip_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".5"
style="?android:attr/buttonBarButtonStyle"/>
<Button
android:id="#+id/button_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".5"
style="?android:attr/buttonBarButtonStyle"/>
</LinearLayout>
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>

Android: Transparent status bar with dynamic actionBar colors and DrawerLayout

I have an activity with a DrawerLayout. Our client requires us to dynamically change the action bar color and the corresponding status bar color of this activity depending upon the item selected from the DrawerLayout. This is easily done. However, my problem is that I am not being able to keep the status bar transparent when I dynamically change the status bar color. When I open the drawer, the colored status bar covers the top of the DrawerLayout like this:
However, I would like my DrawerLayout to look like this:
This I can do with the following line:
<item name="android:windowTranslucentStatus">true</item>
However, my problem is not that I can't set the transparency of the status bar. My problem is that the dynamic changing of the status bar and action bar color doesn't work with windowTranslucentStatus. My status bar color remains the colorPrimaryDark (the mustard-yellowish color visible on the status bar in the pictures above) even after I call getWindow().setStatusBarColor().
Now, I followed this tutorial and this and this stackoverflow questions among many others, but was unable to resolve the issue. All of these articles say that the ActionBar will move to the top, underneath the status bar (so that the status bar overlaps the action bar) once I set the windowTranslucentStatus to true. Afterwards, I should be able to add some padding to the action bar and simply changing the action bar color would also result in a darker status bar of the same color since the status bar is actually translucent and overlapping my action bar. However, for some reason, this does not happen in my case. The action bar stays where it is whether I set fitsSystemWindows to true or false or remove the attribute altogether. The action bar is always below the status bar which is, of course, always yellow if I set transparency.
I have also tried setting an alpha to the status bar color when changing it programmatically. This does make the status bar somewhat transparent, but it looks odd since it is not really dark anymore. Removing the CoordinatorLayout is of no help, either. I have spent several hours trying to fix this and am quite frustrated now. Any help is greatly appreciated.
My activity_main:
<?xml version="1.0" encoding="utf-8"?>
<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">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<include layout="#layout/nav_header_main" />
<android.support.v7.widget.RecyclerView
android:id="#+id/nav_menu_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/nav_header_height"
android:clipToPadding="false"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/size_14dp"
app:layoutManager="LinearLayoutManager" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
And here is the XML for my app_bar_main:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<FrameLayout
android:id="#+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/AppTheme.PopupOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<com.quintype.sakshipost.Widgets.CustomMaterialSearchView
android:id="#+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
Your problem is caused because getWindow().setStatusBarColor() does not work well with the DrawerLayout. In order to keep your status bar translucent as well as being able to change its color, you have to follow the process below:
Add/modify the following theme in your v21/styles.xml file as below:
<style name="AppTheme.NoActionBar" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
This is the theme that the standard DrawerLayout uses (assuming, of course, that you are using this theme in the activity that has the DrawerLayout). This will make your status bar translucent, as you already know.
Next, remove android:fitsSystemWindows="true" from the CoordinatorLayout in your app_bar_main.
Next, wherever you are changing the color of the toolbar/status bar, use drawerLayout.setStatusBarBackground(colorDrawable) using the same color you use for the toolbar (assuming, of course, that the reference to your DrawerLayout is called drawerLayout). Note that the drawerLayout.setStatusBarBackground() method takes a Drawable object, unlike the window.setStatusBarColor() method, which takes an int color, so you may have to convert your color to a drawable using something like this:
new ColorDrawable(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
This will make sure that your status bar is translucent as well as give it the ability to change colors. Hope you are able to get this to work.
As doc says here, FLAG_TRANSLUCENT_STATUS must not be set.
For this to take effect, the window must be drawing the system bar backgrounds with FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS and FLAG_TRANSLUCENT_STATUS must not be set.
I do this in my app like this.
<style name="AppTheme" parent="Theme.AppCompat.Dark">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
the colorPrimary will set the status bar color, but only if you restart the activity.
so set that to a transparent black color, then in your code restart the activity. You can make more than one style in styles, with different colorPrimary values, then in your activity do this.
//onClick or condition statement here
setTheme(R.style.AppThemeLight);
setContentView(R.layout.activity_link_manager_light);
restart();
public void restart(){
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage( getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
I don't think you need to reset the contentview unless you are switching layouts as well, not sure you can try resetting it to the same layout if it's not working without it.
This definitely works for me but i've never tried to use a transparent value.
You can use this method to reset the entire app theme and switch to a new layout that has different colors hardcoded into it, just leave all the id's the same on the layout and in code you will get the right id as long as you reference the findViewByID AFTER you have setContentView to the proper layout that has the ID you call in it somewhere. The id's for each layout are different but you will always get the ID of the layout that is currently set with setContentView at the time you call findViewByID.
you can also save your current theme to a sharedpref file and use a switch to set the theme upon applaunch before setContentView is called (otherwise the statusbar color won't change)
consider this code. This is near the start of onCreate by the way
String Theme;
SaveData = getSharedPreferences(SaveFileName,0);
Theme = SaveData.getString("Theme","Default Theme");
switch(Theme){
case "Light Theme":
setTheme(R.style.AppThemeLight);
setContentView(R.layout.activity_link_manager_light);
ListTextViewID = R.id.AppListTextViewLight;
ListRowID = R.layout.app_list_item_light;
break;
The way i set the apptheme before i set the contentview is why the statusbar color change works.

How can I simply change the color of my Toolbar DrawerToggle?

I have a toolbar defined like so:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" >
I have a navigation drawer toggle button on the toolbar enabled in code (the hamburger menu button). I want it to be white but no matter what I do, it never changes color. I saw in an open source app that they set this in the theme:
<item name="colorControlHighlight">#color/white</item>
I tried it, but still no change for me - it's always the dark almost black color.
I am using this open source app for reference since it looks like it has a white menu button: https://github.com/frogermcs/InstaMaterial
I copied it as closely as I could, but my toolbar menu button never changes color. What am I doing wrong?
Make sure that your style is a parent of Theme.AppCompat.Light.DarkActionBar
also, if you have problems with the popup menu, please add this attribute to the Toolbar view app:popupTheme="#style/ThemeOverlay.AppCompat.Light"

adjustResize not working in lollipop and above with translucent status/Nav

There are questions talking about this problem but I didn't solve mine by existed answers.
This is my styles-v21.xml:
<style name="MainTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:colorBackground">#EEEEEE</item>
</style>
I've set windowSoftInputMethod="adjustResize" for related Activity of course.
Here is my layout.xml, notice that the root FrameLayout is used for specific function thus it is needed:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/rl_background"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--This View is used to fill the space of status bar-->
<View
android:id="#+id/statusbar"
android:layout_width="match_parent"
android:layout_height="#dimen/statusbar_size"/>
<!--I've set this toolbar as Actionbar-->
<android.support.v7.widget.Toolbar
android:id="#+id/actionbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_below="#id/statusbar"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/actionbar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Two EditTexts inside -->
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</FrameLayout>
When I don't touch the EditText, everything looks fine: status bar View stays where it should be and navigation bar doesn't overlay content(doen't make content invisible but content is under it in fact).
In similar questions, people often teach us to set fitsSystemWindow="true", I did this to different layouts inside my layout.xml and got different results.
Setting fitsSystemWindow="true" in:
1.FrameLayout:
AdjustResize works, but status bar View now stays below the real status bar. Status bar's color turns to windowBackground. Navigation bar became entirely transparent because it shows other fragment's content where this fragment was added.
2.First RelativeLayout:
AdjustResize works, but status bar View was below real status bar.Navigation bar isn't too transparent to show other fragment but overlays content.
3&4.ScrollView&RelativeLayout inside ScrollView:
AdjustResize doesn't work and others are same to condition 2.
I also used a method to write my own FrameLayout like this:https://stackoverflow.com/a/22266717/3952691 but as the author said, setting bottom will cause error. Because I use translucent navigation bar, I also need to draw bottom inset. And I try its upgrade version:https://gist.github.com/romannurik/8919163, no use too.
Sorry for can't provide pictures but I really need help.Thank you!

Android Material with Extended Toolbar

I'm testing material design and i'm developing an app using extended toolbar. My app is very simple: The main activity extends ActionBarActivity and my layout looks like:
<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"
tools:context=".WeatherActivity"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/my_toolbar"
android:layout_height="128dp"
popupTheme="#style/ActionBarPopupThemeOverlay"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:text="#string/location_placeholder"
android:textAlignment="viewStart"
android:layout_gravity="start"
/>
</LinearLayout>
Now i'd like to show as title the current location. The first thing i'm noticing is in my Android Emulator (API 18) the title doesn't seem to respect material guidelines about left margin bottom margin, it appears on the left side and entered vertically inside the Toolbar. So Should i use tool bar title (toolbar.setTitle) or something else?
Second if i want to create something more complex like Title and a short description (as shown in the material guidelines in the layout structure) what should be my layout?
Thx for your support!
Ok your activity extends ActionBarActivity so you also have to make sure that the theme for this activity is a child of either Theme.AppCompat.NoActionBar or Theme.AppCompat.Light.NoActionBar. If you are not using the Theme.AppCompat variants then you can alternatively add the following lines to your theme:
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
Then all you need to do is add the Toolbar to your layout (which it looks like you already have):
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/my_toolbar"
android:layout_height="128dp"
popupTheme="#style/ActionBarPopupThemeOverlay"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
Then in your activity set the Toolbar to be your ActionBar via setSupportActionBar:
Toolbar mToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(mToolbar);
That last part is where all the magic happens because you're saying "Android, take this Toolbar widget and use it exactly how you would use the SupportActionBar". This means that if you want to set the title/subtitle all you need to do is call:
getSupportActionBar().setTitle("Toolbar Title");
getSupportActionBar().setSubtitle("Toolbar Subtitle");
This also means that you can use the same callbacks to create a menu on the Toolbar.
To answer your questions directly:
So Should i use tool bar title (toolbar.setTitle) or something else?
You can actually use either, toolbar.setTitle() or getSupportActionBar().setTitle()
Second if i want to create something more complex like Title and a short description (as shown in the material guidelines in the layout structure) what should be my layout?
Toolbar supports Titles and Subtitles so you should be set. I would checkout the documentation just to see what all the Toolbar supports. As a general rule, if the Actionbar could do it, the Toolbar can. If you have crazy requirements beyond what is supported by the Toolbar then just remember that the Toolbar is just a fancy ViewGroup so you can add widgets/views just as easily as if it were a LinearLayout.

Categories

Resources