3

I have an Activity which consists of 4 images and onClick of any image I'm opening a Fragment. Also, I have a Navigation Drawer where the profile option opens up a fragment. Since the fields in my ProfileFragment are few there is allot of empty space. And if the user clicks on the empty space, the click event of the image placed in the Activity is executed and that particular Fragment opens up. I have tried to set the background color of the profilefragment to white, but it did not work.

ProfileFragment class :

 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>

On click of the Profile Option in the Navigation Drawer I'm using the following line to open up the fragment :

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

How do I fix this issue? Kindly help me out please..

Rajeev
  • 316
  • 1
  • 7
  • 17
  • Possible duplicate of [How to disable behind view click event Framelayout](http://stackoverflow.com/questions/16377593/how-to-disable-behind-view-click-event-framelayout) – Mike M. Nov 10 '16 at 06:52

1 Answers1

5

write this code in root layout of your fragment

android:clickable="true"

in your case it is FrameLayout so

<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">  
Ravi
  • 34,851
  • 21
  • 122
  • 183