2

我在活动中添加了一个透明工具栏,该工具栏正常工作。问题是我想单击工具栏下的一个元素。尽管元素是可见的(因为工具栏是透明的),但我无法点击该元素,因为事件正在被工具栏捕获。 我该如何解决这个问题?Android可单击的透明工具栏

XML代码我已经是:

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <FrameLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_alignParentTop="true"/> 

     <android.support.v7.widget.Toolbar 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      style="@style/Theme.Transparent" 
      android:layout_height="@dimen/topbar" 
      android:layout_width="match_parent" 
      android:background="?attr/colorPrimary" 
      android:layout_alignParentTop="true" /> 

    </RelativeLayout> 

正如我所说的,它显示在工具栏上透明的片段,但我不能点击它是工具栏下的元素上。

在此先感谢!

+0

我试过了,但它不工作。感谢您的回答! – FVod

+1

@MateusBrandao我不认为这就是@FVod正在寻找的东西。他说他想在“工具栏”下捕捉点击事件。他从来没有提到过“片段”或菜单项。 – Heinrich

+1

哦,我现在看到... –

回答

0

我回答我自己的问题。我创建一个扩展工具栏自定义工具栏视图,其覆盖的onTouchEvent方法:

@Override 
public boolean onTouchEvent(MotionEvent ev) { 
    return false; 
} 

现在它的正常工作。

0

您可以添加android:clickable="false"以不捕获工具栏上的点击或使用自定义OnTouchListener

+0

我试着这样做:iToolbar.setOnTouchListener(新View.OnTouchListener(){ @覆盖 公共布尔onTouch(查看视图,MotionEvent motionEvent){ 返回FALSE; }} );但它不工作,工具栏下的元素没有检测到点击。谢谢您的回答! – FVod

+0

你尝试过'android:clickable =“false”'吗? – Heinrich

+0

是的,我也试过了,但它不起作用 – FVod