tabsLayout
에는 각각 사용자 정의보기가 포함 된 세 개의 탭이 있으며 ImageView
및 TextView
이 있습니다. 탭을 전환하고 아이콘 중 하나를 클릭하면 아이콘 바깥 쪽을 클릭하면 제대로 전환됩니다. 그러나 아이콘을 클릭하면 전환하지 않습니다. 어떻게 해결할 수 있습니까? 사용자 정의보기 탭이있는 Android TabLayout - 아이콘 클릭으로 탭이 전환되지 않습니다.
<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);
관련 코드를 제공 할 수 있습니까? – Mehmed
@Mehmed 책임 코드 – Simon