如何更改选项卡主机:android中的默认图像位置

如何更改选项卡主机:android中的默认图像位置,android,android-layout,tabs,android-tabhost,android-imageview,Android,Android Layout,Tabs,Android Tabhost,Android Imageview,我需要更改选项卡主机内图像的默认位置,我想在单击任何选项卡时将图像显示为指向每个选项卡顶部的图像。现在如何更改选项卡小部件中图像的默认位置? 我的显示选项卡小部件的简单xml代码如下: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:

我需要更改选项卡主机内图像的默认位置,我想在单击任何选项卡时将图像显示为指向每个选项卡顶部的图像。现在如何更改选项卡小部件中图像的默认位置? 我的显示选项卡小部件的简单xml代码如下:

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

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

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

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:layout_marginBottom="-4dp"/>

</LinearLayout>


您可以将
tabwidget
充气到您想要使用的任何视图

例如:

TabWidget布局:
tab\u widget\u custom.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="@drawable/tabwidget_selector"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/tabIndicatorIcon"
        android:layout_width="28dp"
        android:layout_height="28dp"
        android:layout_marginTop="2dp" />

    <TextView
        android:id="@+id/tabIndicatorText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="2dp"
        android:textColor="@color/white" />

</LinearLayout>
使用此方法创建新的
tabwidget

private void initTab() {
        Intent intent;
        TabHost.TabSpec spec;

        spec = tabHost.newTabSpec("Inbox").setIndicator(
                getTabIndicatorView(MainTabActivity.this, "Inbox",
                        R.drawable.inbox_tab_selector));

        spec.setContent(intent);
        tabHost.addTab(spec);

        }
private View getTabIndicatorView(Context context, String tag, int drawable) {
        View view = LayoutInflater.from(context).inflate(
                R.layout.tab_widget_custom, null);
        TextView tv = (TextView) view.findViewById(R.id.tabIndicatorText);
        tv.setText(tag);
        ImageView tabIndicatorIcon = (ImageView) view
                .findViewById(R.id.tabIndicatorIcon);
        tabIndicatorIcon.setBackgroundResource(drawable);
        return view;

    }
private void initTab() {
        Intent intent;
        TabHost.TabSpec spec;

        spec = tabHost.newTabSpec("Inbox").setIndicator(
                getTabIndicatorView(MainTabActivity.this, "Inbox",
                        R.drawable.inbox_tab_selector));

        spec.setContent(intent);
        tabHost.addTab(spec);

        }