tabsLayout
には、3つのタブ(ImageView
とTextView
のカスタムビューがそれぞれ含まれています)があります。 タブを切り替えるときに、タブの1つをクリックすると、アイコンの外側をクリックするとタブが正しく切り替わります。ただし、アイコンをクリックすると、切り替えられません。 これを修正するにはどうすればよいですか?カスタムタブを表示するタブライアウト - アイコンクリックでタブが切り替わらない
私は偽=フォーカス可能にしようとしたが、それは私のために動作しませんでした。
マイカスタムビュー:
<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" />
そして最後に、私のJavaコード:
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