我是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.
还有一种更好的方法(这样你也可以在左,右,上,下对齐图标):
在res/layout中创建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"/>
活动中的
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个侧边图标,如下所示:
setCompoundDrawablesWithIntrinsicBounds(leftDrawable, topDrawable, rightDrawable, bottomDrawable)
https://stackoverflow.com/questions/33749792
复制相似问题