gpt4 book ai didi

android - 在 com.android.support :design:23. 1.0 中更改左侧、顶部、右侧或底部的 TabLayout 图标

转载 作者:IT老高 更新时间:2023-10-28 22:26:31 25 4
gpt4 key购买 nike

我对 Android 开发还很陌生。所以请耐心等待。

一天以来,我一直在尝试将 com.android.support:design:23.1.0 中的图标和文本对齐在同一行。

显然在 com.android.support:design:23.1.0 他们已将默认图标位置更改为顶部,文本在底部。

以前在 com.android.support:design:23.0.1 默认是左侧的图标和与图标在同一行的文本

所以这里有一个简单的方法来解决它(虽然它可能有缺点,idk tbh):

change the version in your app's build.gradle. ex: 23.1.0 to 23.0.1 and build.

还有一种更好的方法来做到这一点(这样你也可以在左、右、上、下对齐图标):

  1. res/layout
  2. 中创建一个 custom_tab.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"/>

2。在你的 Activity java中

TextView newTab = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
newTab.setText("tab1"); //tab label txt
newTab.setCompoundDrawablesWithIntrinsicBounds(your_drawable_icon_here, 0, 0, 0);
tabLayout.getTabAt(tab_index_here_).setCustomView(newTab);

到目前为止,我已经实现了让图标出现在这样的任何一侧:

TabLayout icons

PS:setCompoundDrawablesWithIntrinsicBounds 函数参数是这样的 4 个侧面图标:

setCompoundDrawablesWithIntrinsicBounds(leftDrawable, topDrawable, rightDrawable, bottomDrawable)

最佳答案

你可以使用 tabInlineLabel 属性

<android.support.design.widget.TabLayout
...
app:tabInlineLabel="true"
...
>
</TabLayout>

关于android - 在 com.android.support :design:23. 1.0 中更改左侧、顶部、右侧或底部的 TabLayout 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33749792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com