android-tablayout 相关问题

Android TableLayout提供了一个类似网格的布局来组织信息的行和列。

如何在两个不同的选项卡中处理相同的数据

我有一个用于两种不同类型的类别的选项卡布局:收入和费用。我使用 CategoriesViewModel 获取所有类别,并观察列表是否有任何更改。当选择一个选项卡时...

回答 1 投票 0

如何创建带有点指示器的 Android 视图寻呼机?

可能你们中的许多人(像我一样)在创建带有底部点的 ViewPager 时遇到问题,如下所示: 如何创建这样一个 Android ViewPager?

回答 11 投票 0

如何删除TabLayout工具提示?

我目前正在努力向 XML 添加选项卡布局,但我不知道如何在长按选项卡时删除工具提示。有人知道吗? 这是它看起来像的图像 htt...

回答 2 投票 0

在选项卡布局中使用自定义视图时无法从选项卡中删除填充

我在自定义视图中添加了相对布局,并在选项卡布局中添加了它。我对选项卡使用白色背景,并且没有在选项卡自定义布局中应用任何填充。但我也很...

回答 11 投票 0

如何将菜单设置为AppBarLayout

我是编程新手,我想添加一个设置菜单按钮。 如图所示,我的应用程序不显示三点按钮。 MainActivity.java: 公共类 MainActivity 扩展了 AppCompatAct...

回答 2 投票 0

为什么在使用 Tablayout 和 viewpager 时选项卡在片段中不可见?

所以,我正在开发我的 android 项目,并且正在为我的社区页面(这是一个片段)开发 UI。我正在使用 Tablayout 和 viewpager。我已经完成了所有工作并设置了适配器...

回答 1 投票 0

在 Android 主屏幕小部件内实现选项卡布局,并仅在选项卡项上单击片段切换

我的目标是仅当用户点击选项卡项目时才应更改文本,并禁用垂直/水平滑动。 我的目标是仅当用户点击选项卡项目时才应更改文本,并禁用垂直/水平滑动。 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <RelativeLayout android:id="@+id/tab1Container" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="8dp"> <TextView android:id="@+id/tab1Text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Tab 1 Content" /> </RelativeLayout> <RelativeLayout android:id="@+id/tab2Container" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="8dp"> <TextView android:id="@+id/tab2Text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Tab 2 Content" /> </RelativeLayout> </LinearLayout> public class MyWidgetProvider extends AppWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int appWidgetId : appWidgetIds) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); setTabClickListener(context, views, appWidgetId, R.id.tab1Container, "Tab 1 Clicked"); setTabClickListener(context, views, appWidgetId, R.id.tab2Container, "Tab 2 Clicked"); appWidgetManager.updateAppWidget(appWidgetId, views); } } private void setTabClickListener(Context context, RemoteViews views, int appWidgetId, int containerId, String contentText) { Intent intent = new Intent(context, MyWidgetProvider.class); intent.setAction("TAB_CLICKED"); intent.putExtra("CONTENT_TEXT", contentText); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, appWidgetId, intent, 0); views.setOnClickPendingIntent(containerId, pendingIntent); } @Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); if ("TAB_CLICKED".equals(intent.getAction())) { String contentText = intent.getStringExtra("CONTENT_TEXT"); updateContent(context, contentText); } } private void updateContent(Context context, String contentText) { Toast.makeText(context, contentText, Toast.LENGTH_SHORT).show(); } } 我需要在android widget中实现一个类似开关的按钮,我只是想知道是否可以使用选项卡布局来实现该功能,如果不可能,请建议其他方法 只需尝试使用自定义选项卡布局并根据您的需求进行自定义即可。 Tablayout 提供了停止滚动和设置选项卡重力的方法。

回答 1 投票 0

如何在TabLayout中设置图标大小?

这是我的代码: 私有 TabLayout tabLayout; 私有 int[] tabIcons = { R.mipmap.ic_compass, R.mipmap.ic_place, R.mipmap.ic_passport, R.mipmap.ic_setting }; ...

回答 8 投票 0

更改 Jetpack Compose 中选定的选项卡底线颜色

我正在使用 Kotlin for Android 开发 Jetpack Compose 项目,并且使用 ScrollableTabRow 实现了选项卡布局。 Tabs有底线,我想改变选中的t的颜色...

回答 1 投票 0

移除TabLayout左右内边距

我正在使用选项卡布局,这是我的代码 我正在使用选项卡布局,这是我的代码 <android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabGravity="center" app:tabMode="fixed" android:minHeight="?attr/actionBarSize" app:tabTextColor="#000" app:tabSelectedTextColor="#fff" app:tabIndicatorColor="@android:color/white" android:clipToPadding="false" /> 像这样添加标签 //创建选项卡 TextView tab = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null); tab.setText("主页"); tab.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.ic_home_black_24dp, 0, 0); tabLayout.addTab(tabLayout.newTab().setCustomView(tab)); TextView tab2 = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null); tab2.setText("Report"); tab2.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.ic_trending_up_black_24dp, 0, 0); tabLayout.addTab(tabLayout.newTab().setCustomView(tab2)); TextView tab3 = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null); tab3.setText("Medicine"); tab3.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.ic_home_black_24dp, 0, 0); tabLayout.addTab(tabLayout.newTab().setCustomView(tab3)); TextView tab4 = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null); tab4.setText("More"); tab4.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.ic_trending_up_black_24dp, 0, 0); tabLayout.addTab(tabLayout.newTab().setCustomView(tab4)); 这是我的手机屏幕截图 https://i.stack.imgur.com/kYNs1.png 有两件事 1.如何删除选项卡布局左右两侧的空间? 2.如何更改活动和非活动选项卡的文本和图标颜色 从选项卡布局中的选项卡中删除填充 在 TabLayout 中,您必须将 tabPaddingEnd 和 tabPaddingStart 设置为 0dp。 <android.support.design.widget.TabLayout app:tabPaddingStart="0dp" app:tabPaddingEnd="0dp"/> 通过更改TabLayout所选选项卡的图标颜色 viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); tabLayout.setOnTabSelectedListener( new TabLayout.ViewPagerOnTabSelectedListener(viewPager) { @Override public void onTabSelected(TabLayout.Tab tab) { super.onTabSelected(tab); int tabIconColor = ContextCompat.getColor(context, R.color.tabSelectedIconColor); tab.getIcon().setColorFilter(tabIconColor, PorterDuff.Mode.SRC_IN); } @Override public void onTabUnselected(TabLayout.Tab tab) { super.onTabUnselected(tab); int tabIconColor = ContextCompat.getColor(context, R.color.tabUnselectedIconColor); tab.getIcon().setColorFilter(tabIconColor, PorterDuff.Mode.SRC_IN); } @Override public void onTabReselected(TabLayout.Tab tab) { super.onTabReselected(tab); } } ); 试试这个, <android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@drawable/bg_forum_tab" app:tabIndicatorColor="@color/colorBtnBg" app:tabIndicatorHeight="0dp" app:tabPaddingBottom="-1dp" app:tabPaddingEnd="-1dp" app:tabPaddingStart="-1dp" app:tabPaddingTop="-1dp" style="@style/CustomTabLayoutStyle" app:tabTextColor="@color/colorWhite" /> 像这样设置 tabPaddingStart/tabPaddingEnd/tabPaddingTop/tabPaddingBottom Styles: <style name="CustomTabLayoutStyle" parent="Base.Widget.Design.TabLayout"> <item name="tabSelectedTextColor">@color/tab_text_selected</item> <item name="tabIndicatorColor">@color/tab_indicator</item> <item name="tabTextAppearance">@style/CustomTabTexStyle</item> </style> <style name="CustomTabTexStyle" parent="TextAppearance.Design.Tab"> <item name="android:textSize">14sp</item> <item name="android:textColor">@color/tab_text</item> ... </style> 要调整填充,您可以使用 app:tabMinWidth 或 tabPaddingStart/tabPaddingEnd/tabPaddingTop/tabPaddingBottom <android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabGravity="center" app:tabMode="fixed" app:tabMinWidth="50dp" app:tabPaddingBottom="1dp" app:tabPaddingEnd="1dp" app:tabPaddingStart="1dp" app:tabPaddingTop="1dp" android:minHeight="?attr/actionBarSize" app:tabTextColor="#000" app:tabSelectedTextColor="#fff" app:tabIndicatorColor="@android:color/white" android:clipToPadding="false" /> 简单来说,您可以使用下面的颜色代码 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/tab_background_selected" android:state_selected="true"/> <item android:drawable="@color/tab_background_unselected"/> </selector> 并将其保存在可绘制对象中为 tab_color_selector.xml 并使用 app:tabBackground="@drawable/tab_color_selector" 所以总代码是 <android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabGravity="center" app:tabMode="fixed" app:tabMinWidth="50dp" android:minHeight="?attr/actionBarSize" app:tabTextColor="#000" app:tabSelectedTextColor="#fff" app:tabIndicatorColor="@android:color/white" app:tabBackground="@drawable/tab_color_selector" android:clipToPadding="false" /> 在 tab_background_selected 和 tab_background_unselected 中提供颜色,如 #000000。或者直接使用 #000000 代替 @color/tab_background_unselected 您可以添加属性: app:tabIndicatorFullWidth="false" app:tabIndicatorHeight="0dp" app:tabMinWidth="0dp" app:tabPadding="0dp" app:tabPaddingBottom="0dp" app:tabPaddingEnd="0dp" app:tabPaddingStart="0dp" app:tabPaddingTop="0dp"

回答 4 投票 0

带有 TabLayout 的 ViewPager2 无法正确导航大量选项卡

我有 tablayout 并查看 pager2,如下所示: 我有 tablayout 并查看 pager2,如下所示: <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.google.android.material.tabs.TabLayout android:id="@+id/tabLayout" android:layout_width="match_parent" android:layout_height="34dp" android:background="@color/bgd_color_light" android:clipChildren="false" android:clipToPadding="false" app:tabBackground="@color/bgd_color_light" app:tabGravity="fill" app:tabIndicator="@drawable/tab_indicator_round" app:tabIndicatorAnimationMode="elastic" app:tabIndicatorColor="@color/app_color" app:tabIndicatorGravity="stretch" app:tabMode="auto" app:tabRippleColor="@color/transparent" app:tabSelectedTextColor="@color/white" app:tabTextAppearance="@style/CustomTabText" /> <androidx.viewpager2.widget.ViewPager2 android:id="@+id/vp2" android:layout_width="match_parent" android:layout_height="match_parent" android:clipChildren="false" android:clipToPadding="false" android:orientation="horizontal" /> </LinearLayout> 我正在使用选项卡布局中介器在选项卡之间移动。我有 17 个选项卡,当我单击第 5 个或更多数字选项卡时,视图寻呼机滚动到最后位置。选项卡映射不正确。这是片段适配器代码: package com.ai.wallpaper.adapters import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.lifecycle.Lifecycle import androidx.viewpager2.adapter.FragmentStateAdapter import com.ai.wallpaper.fragments.WallpaperFragment import com.ai.wallpaper.response.models.Category class WallpaperPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle, private val isPremium: Boolean, private val categoryList: MutableList<Category>) : FragmentStateAdapter(fragmentManager, lifecycle) { override fun createFragment(position: Int): Fragment { return WallpaperFragment.newInstance(categoryList[position].id, isPremium) } override fun getItemCount(): Int { return categoryList.size } } // adapter attach vp2.adapter = wallpaperPagerAdapter TabLayoutMediator(tabLayout, vp2) { tab, position -> //tab.text = catList[position].name tab.text = "Tab $position" //WallpaperHttpRequest.printMessage("VP2", position) }.attach() 我认为这是因为您在不使用片段管理器的情况下实例化这些片段。默认情况下,适配器使用片段管理器创建前几页,但随后您返回匿名创建的片段。并且由于片段管理器只能使用默认工厂,因此您需要将这些参数作为参数传递。 override fun createFragment(position: Int): Fragment { return fragmentManager.fragmentFactory.instantiate( classLoader, WallpaperFragment::class.java.name ).also { (it as WallpaperFragment).let { fr -> fr.arguments = Bundle().also { bundle -> bundle.putInt("ID_ARG", categoryList[position].id) bundle.putInt("PPREMIUM_ARG", isPremium) } } } }

回答 1 投票 0

如何在Android中制作垂直TabLayout

嗨,我正在尝试制作垂直选项卡布局。尝试使用旋转视图,但它无助于它不重新计算视图高度和视图。任何帮助将不胜感激,以实现以下结果。

回答 3 投票 0

如何在以编程方式滚动时禁用 tabLayout 滚动动画?

当活动开始时,我以编程方式更改选项卡布局的位置,但在以参数方式更改选项卡布局位置时,它会提供从第 0 个选项卡到我所在的选项卡的滚动动画

回答 2 投票 0

使用 TabLayout 时如何更改选项卡背景颜色?

这是我在主要活动中的代码 公共类 FilterActivity 扩展 AppCompatActivity { @覆盖 protected void onCreate(Bundle savingInstanceState) { super.onCreate(savedInstanceSta...

回答 14 投票 0

如何制作垂直选项卡布局

有什么方法可以使我的选项卡布局处于垂直模式吗? 我尝试以垂直模式制作此选项卡布局,我在任何地方搜索但从未找到以垂直模式制作它的方法。 注意:我正在使用...

回答 1 投票 0

如何在Android Studio中制作垂直TabLayout

嗨,我正在尝试制作垂直选项卡布局。尝试使用旋转视图,但它无助于它不重新计算视图高度和视图。任何帮助将不胜感激,以实现以下结果。

回答 3 投票 0

更新 TabLayout 标题

我有一个 TabLayout(来自设计库),它通过 FragmentPagerAdapter 填充了 2 个片段(都包含一个项目列表)。 这两个列表相互关联:T...

回答 2 投票 0

SmartTabLayout 点击时的波纹效果

我正在使用 SmartTabLayout,当我单击或选择选项卡时,我想禁用波纹效果和一些灰色方形背景。 我将此代码添加到我的 xml 但仍然不起作用: 应用程序:tabBackground =“?...

回答 2 投票 0

viewpager 中的选项卡布局问题

我正在每个选项卡片段中使用动态列表视图制作动态选项卡。问题是当我在两个连续选项卡之间切换时,会显示前一个选项卡的 xml,但是当我单击非

回答 1 投票 0

E/iardini.error0:无效 ID 0x00000001 - 错误资源 ID

我目前遇到一个错误,该错误继续降低我的应用程序的性能。 该错误不会导致应用程序关闭或崩溃,也不会导致向控制台写入异常。 ...

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.