1

when i click on my tab layout tabs, its shows me little gray color.

how can i set transparency on touch.

Here is my xml code

   <ViewPager
    android:id="@+id/viewpager"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    />
   <android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0"
    android:layout_marginBottom="-3dp"
    android:layout_alignParentBottom="true"
    app:tabMode="fixed"
    app:tabGravity="fill"
    android:layout_marginLeft="50dp"
    android:layout_marginRight="50dp"
    android:background="@null"
    android:overScrollMode="never" /> 

.java file

    tabLayout.setFocusableInTouchMode(false); //Not Working
    tabLayout.setFocusable(false); //Not Working

Tab layout effect

Viveka Patel
  • 666
  • 7
  • 17

5 Answers5

1

app:tabRippleColor="@android:color/transparent"

Ram
  • 21
  • 1
0

How to Remove onTouch Focus of TabLayout

tabLayout.clearFocus();

Note: When a View clears focus the framework is trying to give focus to the first focusable View from the top. Hence, if this View is the first from the top that can take focus, then all callbacks related to clearing focus will be invoked after which the framework will give focus to this view.

Source : Android Documentation

bastami82
  • 5,955
  • 7
  • 33
  • 44
0

Try this:

app:tabBackground="@android:color/transparent"
xenteros
  • 15,586
  • 12
  • 56
  • 91
douya
  • 9
  • 1
0

I guess this is not a good practice for accessibility, but you can find here an approach that worked for me.

Solution: Setting the TabLayout to not focusable isn't enough, you have to recursively call the Childs and disable the focus for each one. I wrote this method to set the focus recursively.

private void setFocusable(View view, boolean focus) {
    view.setFocusable(focus);
    if(view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for(int i = 0; i<viewGroup.getChildCount(); i++) {
            setFocusable(viewGroup.getChildAt(i), focus);
        }
    }
}

Example of use:

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View layout = inflater.inflate(getLayoutId(), container, false);

    viewPager = layout.findViewById(R.id.viewPager);

    pagerAdapter = getPagerAdapter();
    viewPager.setAdapter(pagerAdapter);
    viewPager.requestFocus();

    tabLayout = layout.findViewById(R.id.tabLayout);
    tabLayout.setupWithViewPager(viewPager, true);

    // disabling focus on TabLayout
    setFocusable(tabLayout, false);

    return layout;
}
lasnow
  • 80
  • 5
0

One liner solution :) . To suppress focus on Tablayout children views use the code fragment below :

tabLayout.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
Igor Zinin
  • 331
  • 3
  • 5