2016-11-10 76 views
2

我有一个Activity其中包含4张图片和onClick任何图像我打开Fragment。此外,我有一个Navigation Drawer其中配置文件选项打开fragment。由于我的ProfileFragment中的字段很少,所以有空余空间。如果用户点击空白区域,则执行放置在Activity中的图像的点击事件,并且该特定的Fragment打开。我试图将profilefragment的背景颜色设置为white,但它不起作用。点击片段中的空白空间执行活动事件

ProfileFragment类:

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    View view = inflater.inflate(R.layout.fragment_profile, container, false); 
    ButterKnife.bind(this, view); 
    view.setBackgroundColor(Color.WHITE); 
    return view; 
} 

profile_fragment.xml

<FrameLayout 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" 
tools:context="com.six30labs.mis.fragments.ProfileFragment"> 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

       <EditText 
         android:id="@+id/empCompanyName" 
         style="@style/MyTextViewStyle"        
         android:hint="Company Name" 
         android:inputType="text" /> 


       <EditText 
         android:id="@+id/empPhoneNumber" 
         style="@style/MyTextViewStyle" 
         android:hint="Employee PhNo" 
         android:inputType="text" /> 

       <EditText 
         android:id="@+id/empEmail" 
         style="@style/MyTextViewStyle" 
         android:hint="Employee Email" 
         android:inputType="text" /> 

      <Button 
        android:id="@+id/editProfileBtn" 
        android:text="Edit" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
         /> 
    </LinearLayout> 
</FrameLayout> 

论我用下面的行开拓片段Navigation Drawer配置文件选项的点击:

fragment = new ProfileFragment(); 
getSupportFragmentManager().beginTransaction().replace(R.id.container_view,fragment).addToBackStack("Profile").commit(); 

如何解决此问题?请帮我请..

+0

的可能的复制[如何禁用后面视图点击事件Framelayout](http://stackoverflow.com/questions/16377593/how-to-disable-behind-view-click-event-framelayout) –

回答

1

写这段代码在你的片段根布局

android:clickable="true" 
在你的情况下,它是 FrameLayout

所以

<FrameLayout 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:clickable="true" 
    tools:context="com.six30labs.mis.fragments.ProfileFragment"> 
+1

嘿谢谢分配!解决了这个问题!肯定会阅读有关:) – Rajeev