2016-11-10 80 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