Java 我没有得到自定义选项卡的图标
在我的应用程序中,我正在使用自定义选项卡。在这里,我添加图标亲语法的图像视图。除第一个选项卡外,图像正在正确添加。谁能帮帮我吗。 下面是我的代码Java 我没有得到自定义选项卡的图标,java,android,android-layout,Java,Android,Android Layout,在我的应用程序中,我正在使用自定义选项卡。在这里,我添加图标亲语法的图像视图。除第一个选项卡外,图像正在正确添加。谁能帮帮我吗。 下面是我的代码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tabsLayout" android:layout_width="fill_parent" android:layout_height="fi
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabsLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/tab_bg_selector"
android:padding="2dip"
android:gravity="center"
android:orientation="vertical">
<ImageView android:id="@+id/tabicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/tabsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="12dip"
android:textColor="@drawable/tab_text_selector"
/>
</LinearLayout>
试着用那种形式
为“制作”选项卡提供图像
这里我使用的是自定义选项卡
public class CustomTabActivity extends Activity {
private TabHost mTabHost;
private void setupTabHost() {
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// construct the tabhost
setContentView(R.layout.main);
setupTabHost();
mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
setupTab(new TextView(this), "Find Gifts",R.drawable.findgifts);
setupTab(new TextView(this), "Tracked Items",R.drawable.items);
setupTab(new TextView(this), "Preferences",R.drawable.preferences);
}
private void setupTab(final View view, final String tag,int drawable) {
View tabview = createTabView(mTabHost.getContext(), tag, drawable);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() {
public View createTabContent(String tag) {
return view;
}
});
mTabHost.addTab(setContent);
}
private static View createTabView(final Context context, final String text,int drawable) {
View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
ImageView tabicon = (ImageView) view.findViewById(R.id.tabicon);
tabicon.setBackgroundResource(drawable);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
}