android7.0 Toolbar焦点,Android appcompat toolbar stretches when searchview gets focus

I would like to share my experience but before that I want to dropped this comment. So far, I really find this CoordinatorLayout shenanigans buggy and not worthy of being dropped in the SDK. Its just buggy. When it behaves like this erratically, the architecture on the xml layout is not much of a help to figure out whats going on. I followed the examples religiously and none of them worked.

Having said that, I am using the build tools version v24.0.2 (The latest as of this writing) and my situation may be of different than the rest. So I am putting this answer along with other answers here.

In my case, I am using this library for NavigationDrawer

As some answers here pointed out, its the navigation drawer. I tried not using that library and still having the problem. I have CoordinatorLayout as the parent layout of my two activities and programatically inserts the NavigationDrawer as instructed by the library author. The expanding Toolbar the size of the screen when focusing on an EditText is still there. Therefore, in my case, the problem is not coming from there.

Here's what I did in my case:

I removedfitsSystemWindows from the CoordinatorLayout layout of the activity. Contrary to what other people suggested here.

I am pasting my entire activity layout here:

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/coordinatorlayout_homescreen"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".activity.HomeScreenActivity">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:fitsSystemWindows="true"

android:theme="@style/AppTheme.AppBarOverlay">

android:id="@+id/collapsingtoolbarlayout_homescreen"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:fitsSystemWindows="true"

app:contentScrim="?attr/colorPrimary"

app:expandedTitleMarginStart="64dp"

app:expandedTitleMarginEnd="48dp"

app:layout_scrollFlags="scroll|enterAlwaysCollapsed">

android:id="@+id/toolbar_homescreen"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:fitsSystemWindows="true"

app:layout_collapseMode="pin"/>

android:layout_width="match_parent"

android:layout_height="match_parent"

app:layout_behavior="@string/appbar_scrolling_view_behavior">

android:id="@+id/framelayout_homescreen"

android:layout_width="match_parent"

android:layout_height="match_parent" />

I did this on another activity and it works as expected. I don't have the expanding Toolbar anymore. But this problem occurred. I am about to pull my hair out. The status bar became white. Phoenix Wang solution on that post fix it for me and I quote his answer:

I found the answer in this link:Status Bar Color not changing with

Relative Layout as root element

So it turns out we need remove the

@android:color/transparent in

styles.xml(v21). And it works just fine for me.

My only concern is how will this solution holds in the upcoming updates. CoordinatorLayout should not be behaving like that.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值