カスタムタブレイアウト実装 WIP

This commit is contained in:
r-ca 2024-01-28 15:01:51 +09:00
parent 457eabcdf4
commit 6f9384039a
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9
3 changed files with 14 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import androidx.viewpager2.widget.ViewPager2;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -130,7 +131,14 @@ public class ViewerContainerFragment extends Fragment {
}
// Attach tab layout to view pager
new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> tab.setText(viewerViewPagerAdapter.getTabTitle(position))).attach();
new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
View customView = LayoutInflater.from(getContext()).inflate(R.layout.viewer_custom_tab, null);
TextView textView = customView.findViewById(R.id.tab_title);
textView.setText(viewerViewPagerAdapter.getTabTitle(position));
tab.setCustomView(customView);
}).attach();
}
/**

View File

@ -40,7 +40,9 @@
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
app:tabMode="scrollable"
/>
<ProgressBar
android:id="@+id/loading_progress_bar"

View File

@ -6,14 +6,14 @@
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView"
android:id="@+id/tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TAB TITLE"
android:layout_gravity="center"/>
<ImageButton
android:id="@+id/imageButton"
android:id="@+id/tab_modify"
android:layout_marginLeft="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"