2017-09-29 1 views
1

tabsLayout에는 각각 사용자 정의보기가 포함 된 세 개의 탭이 있으며 ImageViewTextView이 있습니다. 탭을 전환하고 아이콘 중 하나를 클릭하면 아이콘 바깥 쪽을 클릭하면 제대로 전환됩니다. 그러나 아이콘을 클릭하면 전환하지 않습니다. 어떻게 해결할 수 있습니까? 사용자 정의보기 탭이있는 Android TabLayout - 아이콘 클릭으로 탭이 전환되지 않습니다.

enter image description here

나는 거짓 = 포커스와 함께했지만, 나를 위해 작동하지 않았다.

내 사용자 정의보기 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/customButton" 
    android:layout_width="match_parent" 
    android:layout_height="80dp" 
    android:clickable="false" 
    android:focusable="false" 
    android:focusableInTouchMode="false" 
    android:alpha="0.5" 
    android:orientation="vertical"> 

    <ImageButton 
     android:id="@+id/icon" 
     android:layout_width="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_height="0dp" 
     android:layout_weight="4" 
     android:clickable="false" 
     android:focusable="false" 
     android:focusableInTouchMode="false" 
     android:background="@android:color/transparent" 
     android:onClick="airspacesButtonOnClick" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:tint="@color/colorIcons"/> 

    <TextView 
     android:id="@+id/string" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:clickable="false" 
     android:focusable="false" 
     android:focusableInTouchMode="false" 
     android:textAlignment="center" 
     android:textSize="12sp" /> 
</LinearLayout> 

내 TabLayout :

<android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="80dp" 
     app:tabIndicatorColor="@color/colorButton" 
     app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget" 
     app:tabMode="fixed" 
     app:tabGravity="fill"/> 
<android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

그리고 마지막으로 내 자바 코드 : 당신은 false로 clickable를 설정하여 이미지 뷰가 unclickable 만들기 위해 노력하고

int[] iconIds = {R.drawable.ic_profile, R.drawable.ic_plane, R.drawable.ic_document}; 
int[] labelIds = {R.string.menu, R.string.menu, R.string.menu}; 
View customView; 
for (int i = 0; i < tabLayout.getTabCount(); i++) { 
customView = getActivity().getLayoutInflater().inflate(R.layout.custom_icon, null); 
customView.findViewById(R.id.icon).setBackgroundResource(iconIds[i]); 

((TextView) customView.findViewById(R.id.string)).setText(labelIds[i]); 
tabLayout.getTabAt(i).setCustomView(customView); 
+0

관련 코드를 제공 할 수 있습니까? – Mehmed

+0

@Mehmed 책임 코드 – Simon

답변

1

onClick을 사용하면 이미지가 무시되고 이미지 뷰는 클릭 할 수있게됩니다. 이득. 그렇기 때문에 ImageView를 클릭 할 때 ImageView 자체에서 클릭이 발생하고 부모에게 전파되지 않습니다. 그래서 사용자 정의 탭 레이아웃의 이미지 뷰에서이 줄을 제거해야합니다 :이 줄을 제외하고

android:onClick="airspacesButtonOnClick" 

, 그것은 주어진 코드와 레이아웃을 날 위해 일했습니다.

+0

을 추가했습니다. 감사합니다. :) – Simon

관련 문제