国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

com.google.android.material.tabs.TabLayout

這篇具有很好參考價(jià)值的文章主要介紹了com.google.android.material.tabs.TabLayout。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

一、布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical"
    tools:context=".main.MainActivity">


    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/main_viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="65dp"/>

    <com.google.android.material.tabs.TabLayout
            android:id="@+id/tab_layout_main"
            android:layout_width="match_parent"
            android:background="@color/white"
            app:tabGravity="fill"
            app:tabMaxWidth="0dp"
            app:tabMode="fixed"
            android:layout_height="65dp" />

</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@color/transparent"
    android:gravity="center">

    <CheckBox
        android:id="@+id/tb_main_tab_checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@null"
        android:checked="false"
        android:focusable="false"
        android:clickable="false"
        android:text="" />

    <TextView
        android:id="@+id/tv_main_tab_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/dimen_4"
        android:text=""
        android:textSize="@dimen/font_12"
        android:clickable="false"
        android:textColor="@drawable/common_tab_text_color" />

</LinearLayout>

?文章來源地址http://www.zghlxwxcb.cn/news/detail-832815.html

二、界面中使用

private String[] tabs;
private int[] resIds;
? tabs = this.getResources().getStringArray(R.array.main_tab_btn_name);
        resIds = new int[]{R.drawable.icon_main_tab_bg,
                R.drawable.icon_project_tab_bg,
                R.drawable.icon_block_tab_bg,
                R.drawable.icon_me_tab_bg};

        ViewPagerScrollAdapter scrollAdapter = new ViewPagerScrollAdapter(getSupportFragmentManager(), getLifecycle(), fragmentList);

        binding.mainViewpager.setAdapter(scrollAdapter);

        binding.mainViewpager.setUserInputEnabled(false);
//        binding.mainViewpager.setOffscreenPageLimit(2);
        binding.tabLayoutMain.setTabTextColors(R.color.color_3D80FC, R.color.color_3D80FC);

        mediator = new TabLayoutMediator(binding.tabLayoutMain, binding.mainViewpager, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                //自定義TabView
                View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.item_main_tab_view, null);
                view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT,1));

                TextView tabView = view.findViewById(R.id.tv_main_tab_text);
                tabView.setText(tabs[position]);


                CheckBox checkBox = view.findViewById(R.id.tb_main_tab_checkbox);
                checkBox.setBackgroundResource(resIds[position]);
                if (position == 0) {
                    checkBox.setChecked(true);
                    tabView.setSelected(true);
                }

                tab.setCustomView(view);
            }
        });

        binding.tabLayoutMain.setSelectedTabIndicatorHeight(0); //去掉下劃線
        binding.tabLayoutMain.setTabRippleColor(ColorStateList.valueOf(getContext().getResources().getColor(R.color.white)));//去掉黑色背景

        //要執(zhí)行這一句才是真正將兩者綁定起來
        mediator.attach();
    binding.tabLayoutMain.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                selectOrLogin();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                ((CheckBox) tab.getCustomView().findViewById(R.id.tb_main_tab_checkbox)).setChecked(false);
                tab.getCustomView().findViewById(R.id.tv_main_tab_text).setSelected(false);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
                selectOrLogin();
            }
        });
?
ViewPagerScrollAdapter?
public class ViewPagerScrollAdapter extends FragmentStateAdapter  {
    private ArrayList<Fragment> fragmentList;

    public ViewPagerScrollAdapter(@NonNull Fragment fragment) {
        super(fragment);
    }

    public ViewPagerScrollAdapter(@NonNull FragmentActivity fragmentActivity,ArrayList<Fragment> fragmentList) {
        super(fragmentActivity);
        this.fragmentList=fragmentList;
    }

    @Override
    public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        recyclerView.setItemViewCacheSize(fragmentList.size());
    }

    public ViewPagerScrollAdapter(@NonNull FragmentManager fragmentManager, @NonNull Lifecycle lifecycle,ArrayList<Fragment> fragmentList) {
        super(fragmentManager, lifecycle);
        this.fragmentList=fragmentList;
    }


    @NonNull
    @Override
    public Fragment createFragment(int position) {
        // 返回Fragment
        return fragmentList.get(position);
    }

    @Override
    public int getItemCount() {
        // 獲取Fragment數(shù)量
        return fragmentList.size();
    }

}

到了這里,關(guān)于com.google.android.material.tabs.TabLayout的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Android——viewpage2+tablayout+fragment動(dòng)態(tài)添加刪除

    Android——viewpage2+tablayout+fragment動(dòng)態(tài)添加刪除

    一、簡介: 1、添加和刪除按鈕可動(dòng)態(tài)添加刪減tab頁面 2、獲取每個(gè)fragment數(shù)據(jù)頁上的數(shù)據(jù) 3、為每個(gè)數(shù)據(jù)頁賦值 二、 效果圖: 三、實(shí)現(xiàn): 主要功能實(shí)現(xiàn):( ViewPage2Fragment.java ) 先初始化適配器 frament數(shù)據(jù)頁(ViewPage2DataFragment.java) 適配器(FragmentStateViewPager2Adapter.java) 主布

    2024年02月16日
    瀏覽(31)
  • android 關(guān)于TabLayout聯(lián)動(dòng)ViewPager2 實(shí)現(xiàn)底部導(dǎo)航欄

    android 關(guān)于TabLayout聯(lián)動(dòng)ViewPager2 實(shí)現(xiàn)底部導(dǎo)航欄

    最近在心血來潮想寫在app 不過我關(guān)于android可以說是0基礎(chǔ) 在寫底部導(dǎo)航欄的時(shí)候去問了大佬才知道TabLayout和ViewPager 花了兩天才看懂... 這里只是簡單介紹因?yàn)槲也粶?zhǔn)備專門做安卓軟件所以在學(xué)的途中很多地方?jīng)]有認(rèn)真記 本篇文章使用的代碼是Java 這里官方是有將兩個(gè)進(jìn)行聯(lián)動(dòng)

    2024年01月25日
    瀏覽(24)
  • Android 設(shè)置TabLayout選中后的字體、大小、顏色等設(shè)置

    初始化 1)在xml中設(shè)置顏色變化 其中,tabTextColor未未選中時(shí)的顏色,tabSelectedTextColor為選中時(shí)的顏色。 2)對已定義好的TabLayout進(jìn)行處理。 在監(jiān)聽器中設(shè)置樣式 在選中時(shí)或未選中時(shí),獲取已設(shè)置的TextView,然后可以去設(shè)置需要的大小、加粗等變化。 我做了一個(gè)簡單的封裝,這

    2024年02月12日
    瀏覽(23)
  • Android開發(fā):利用Android Studio自帶的底部導(dǎo)航欄和ViewPager+TabLayout創(chuàng)建頂部導(dǎo)航欄

    Android開發(fā):利用Android Studio自帶的底部導(dǎo)航欄和ViewPager+TabLayout創(chuàng)建頂部導(dǎo)航欄

    目錄 效果圖 底部導(dǎo)航欄 ?編輯 頂部導(dǎo)航欄 底部導(dǎo)航欄首個(gè)Fragment代碼 適配器代碼 頂部導(dǎo)航欄首個(gè)Fragment代碼 ?頂部導(dǎo)航欄另外三個(gè)Fragment代碼 ??編輯 頂部導(dǎo)航欄四個(gè)Fragment的XML 補(bǔ)充 學(xué)Android開發(fā)開始實(shí)操,第一步肯定要把大致布局搞定。做這個(gè)布局用到的知識難點(diǎn)有fr

    2024年02月03日
    瀏覽(33)
  • Android kotlin 實(shí)現(xiàn)仿蜜源ViewPager和指示器對應(yīng)上面TabLayout功能

    Android kotlin 實(shí)現(xiàn)仿蜜源ViewPager和指示器對應(yīng)上面TabLayout功能

    在 app 的 build.gradle 在添加以下代碼 1、 TabLayout : implementation \\\'com.google.android.material:material:1.1.0\\\' 2、 implementation \\\'com.github.li-xiaojun:StateLayout:1.3.4\\\' //allprojects {…增加:maven { url ‘https://jitpack.io’ }…} 3、 implementation \\\'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.6\\\' ,這個(gè)里面帶的適配

    2024年02月09日
    瀏覽(22)
  • Android中實(shí)現(xiàn)Material3主題

    Android中實(shí)現(xiàn)Material3主題

    Material 3是由Google引入的一種設(shè)計(jì)系統(tǒng),通過采用一套設(shè)計(jì)原則、指南和組件,提供統(tǒng)一直觀的用戶體驗(yàn)。 在本篇文章中,您將學(xué)習(xí)如何: 在您的Android應(yīng)用程序中應(yīng)用Material 3主題。 如何使用Material 3屬性應(yīng)用于您的視圖。 如何應(yīng)用動(dòng)態(tài)著色。 首先需要引入material組件以來:

    2024年01月17日
    瀏覽(23)
  • Android開發(fā)的UI設(shè)計(jì)——Material Design

    Android開發(fā)的UI設(shè)計(jì)——Material Design

    Material Design 是用于指導(dǎo)用戶在各種平臺和設(shè)備上進(jìn)行視覺、動(dòng)作和互動(dòng)設(shè)計(jì)的全面指南。如需在您的 Android 應(yīng)用中使用 Material Design,請遵循?Material Design 規(guī)范中定義的準(zhǔn)則,并使用?Material Design 支持庫中提供的新組件和樣式。 安卓中的Material Design 作為Google旗下的一員——

    2024年02月13日
    瀏覽(40)
  • 【學(xué)習(xí)】https://gitee.com/DingJiaxiong

    【學(xué)習(xí)】https://gitee.com/DingJiaxiong

    【學(xué)習(xí)】https://gitee.com/DingJiaxiong 0 前言 事情是這樣,我準(zhǔn)備把之前所有的筆記都放到Gitee 上了 不用GitHub … 就別問原因了。【方便大家自取】 OK,這幾個(gè)月多多少少也寫了2000 + 篇Markdown 筆記了,有些現(xiàn)在還沒發(fā)出博客,因?yàn)橐惶熘荒馨l(fā)20 篇。 這些筆記都是自己看B站視頻做的

    2024年02月01日
    瀏覽(21)
  • 使用gitee上傳代碼報(bào)錯(cuò):git@gitee.com: Permission denied (publickey),如何配置GitEE公鑰

    使用gitee上傳代碼報(bào)錯(cuò):git@gitee.com: Permission denied (publickey),如何配置GitEE公鑰

    git@gitee.com: Permission denied (publickey). Could not read from remote repository. ?Please make sure you have the correct access rights and the repository exists. Permission denied (publickey) 沒有權(quán)限的publickey(公鎖) ,出現(xiàn)這錯(cuò)誤一般是以下兩種原因: 客戶端與服務(wù)端未生成 ssh key 客戶端與服務(wù)端的ssh key不匹配 找到

    2024年02月05日
    瀏覽(55)
  • Android Material組件庫(日期選擇和時(shí)間選擇器)基本使用

    Android Material組件庫(日期選擇和時(shí)間選擇器)基本使用

    原文:Android Material組件庫(日期選擇和時(shí)間選擇器)基本使用 - Stars-One的雜貨小窩 簡單的封裝下Material組件里的日期選擇器和時(shí)間選擇器的使用方法 需要添加Material組件庫的依賴(不過后面新版本Android Studio創(chuàng)建的新項(xiàng)目都會(huì)有此依賴了...)

    2024年02月05日
    瀏覽(34)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包