首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在com.android.support中更改左上右下的设计图标。支持: TabLayout :23.1.0

在com.android.support中更改左上右下的设计图标。支持: TabLayout :23.1.0
EN

Stack Overflow用户
提问于 2015-11-17 13:27:46
回答 4查看 19.7K关注 0票数 29

我是android开发的新手。所以请耐心听我说。

我已经尝试在com.android.support:design:23.1.0中将图标和文本在同一行中对齐一天了。

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

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

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

代码语言:javascript
复制
change the version in your app's build.gradle. ex: 23.1.0 to 23.0.1 and build.

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

res/layout中创建custom_tab.xml

代码语言:javascript
复制
<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"/>

活动中的

  1. java

代码语言:javascript
复制
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);

到目前为止,我已经实现了让图标出现在任何一侧,如下所示:

PS:setCompoundDrawablesWithIntrinsicBounds函数参数是4个侧边图标,如下所示:

代码语言:javascript
复制
setCompoundDrawablesWithIntrinsicBounds(leftDrawable, topDrawable, rightDrawable, bottomDrawable)
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33749792

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档