android – 在3个选项卡上添加图像

如何将图像添加到选项卡?目前我可以将标签移动到底部但不知道如何将LL Tab1,LL Tab2,LL Tab3更改为icon.Am我在正确的路径上?任何帮助将不胜感激.

xml代码

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="5dp" >


        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp"
            android:layout_weight="1" >

            <LinearLayout
                android:id="@+id/ll_tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <LinearLayout
                android:id="@+id/ll_tab2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <LinearLayout
                android:id="@+id/ll_tab3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />
        </FrameLayout>
        <TabWidget
            android:id="@android:id/tabs"
            android:background="@color/light_gray"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"/>
    </LinearLayout>

</TabHost>

有人可以帮忙吗?非常感谢 !

解决方法

尝试使用 TabLayoutAndroid Design Support Librarymaterial design guidelines for tabs.

The Design library’s TabLayout implements both fixed tabs,where the
view’s width is divided equally between all of the tabs,as well as
scrollable tabs,where the tabs are not a uniform size and can scroll
horizontally.

要实现TabLayout,请检查此guidehow to add the icon for swipeable tabs以使用setIcon将图标设置为选项卡.

final int[] ICONS = new int[]{
        R.drawable.ic_action_document,R.drawable.ic_action_tick,R.drawable.ic_action_trash};
        ....
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);

tabLayout.getTabAt(0).setIcon(ICONS[0]);
tabLayout.getTabAt(1).setIcon(ICONS[1]);
tabLayout.getTabAt(2).setIcon(ICONS[2]);

要在TabLayout检查中设置底部的选项卡 – How can I set tabs at the bottom and also hide top actionbar?,将TabLayout放在relativeLayout中并将其与父底部对齐:

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    app:tabMode="fixed"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:elevation="6dp"
    app:tabTextColor="#d3d3d3"
    app:tabSelectedTextColor="#ffffff"
    app:tabIndicatorColor="#ff00ff"
    android:minHeight="?attr/actionBarSize"
    android:layout_alignParentBottom="true"
    />

虽然您可以将标签布局放在底部,但根据Pure Android指南,尽量不要使用底部标签栏.

Other platforms use the bottom tab bar to switch between the app’s views. Per platform convention,Android’s tabs for view control are shown in action bars at the top of the screen instead.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...