关于Android长按出现复制粘贴栏在顶部占位问题解决方法

关于Android长按出现复制粘贴栏在顶部占位问题解决方法

大家都知道,在Android长按WebViewEditText等组件时,4.0以上的系统顶部会出现复制/粘贴栏(以下使用使用操作栏作为描述),而如果有使用ActionBar,则操作栏就会悬浮在ActionBar上,但如果没有使用ActionBar,则会插入顶部并且占居一定的位置,如果是自定义的顶部栏,那么新插入的操作栏就会影响美观与体验(如下图)。所以,带着这个问题,去研究与分析Activity的界面层次布局,从而找出解决方案。

在研究了一遍ActionBar的界面层次源码后,得到的了解决方法
将操作栏设置为悬浮方式:
1、在Activity使用setContentView方法之前,调用requestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY);

2、如果是继承ActionBarActivity,则调用以下方法
supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_MODE_OVERLAY);

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
这个问题可能与AppBarLayout的滚动效果有关。当你动态设置一个View为GONE时,AppBarLayout会重新计算滚动范围,但是由于布局文件中的空白区域已经被占用了,新的滚动范围可能会出现空白占位问题解决办法是在AppBarLayout中使用`app:layout_scrollFlags="scroll|exitUntilCollapsed"`,并且在你要隐藏的View上添加`app:layout_collapseMode="pin"`。这样当你隐藏这个View时,AppBarLayout会自动调整滚动范围,并且不会出现空白占位问题。 示例代码如下: ```xml <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <android.support.design.widget.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:contentScrim="?attr/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <ImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="200dp" android:scaleType="centerCrop" android:src="@drawable/image" app:layout_collapseMode="parallax" /> <TextView android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:text="Title" android:textColor="@android:color/white" android:textSize="24sp" app:layout_collapseMode="pin" /> <View android:id="@+id/view" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="visible" app:layout_collapseMode="pin" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> ``` 在代码中,我把你要隐藏的View的`android:visibility`属性设置为`visible`,这样在初始状态下它会被显示出来。当你要隐藏它时,可以使用`view.setVisibility(View.GONE)`方法。AppBarLayout会根据你隐藏的View自动调整滚动范围,不会出现空白占位问题
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值