如何在Android Tab Host中将图像添加为Tab指示器?

编程入门 行业动态 更新时间:2024-10-28 20:21:48
本文介绍了如何在Android Tab Host中将图像添加为Tab指示器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我当前正在开发一个显示标签主机的应用程序,标签主机中的每个标签都是一个活动.现在,我要做的是将文本标签指示符替换为图像.这些是我用于实现选项卡宿主活动的代码. TabHostActivity:

I am currently developing an application which a tab host is shown, each one of tab in the tab host is an activity. Now, what I want to do is to replace my text tab indicator as an image. These are the code that I used for implementing my tab host activity. TabHostActivity:

public class TabHostActivity extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tabhost); TabHost tabHost = (TabHost) findViewById (android.R.id.tabhost); TabSpec tab1 = tabHost.newTabSpec("First Tab"); TabSpec tab2 = tabHost.newTabSpec("Second Tab"); TabSpec tab3 = tabHost.newTabSpec("Third Tab"); tab1.setIndicator("Tab1"); tab1.setContent(new Intent(this, Tab1Activity.class)); tab1.setContent(new Intent(this, Tab1Activity.class)); tab2.setIndicator("Tab2"); tab2.setContent(new Intent(this, Tab2Activity.class)); tab3.setIndicator("Tab3"); tab3.setContent(new Intent(this, Tab3Activity.class)); tabHost.addTab(tab1); tabHost.addTab(tab2); tabHost.addTab(tab3); }

}

如您在代码中所见,我将Tab1,Tab2,Tab3设置为我的标签指示符,并希望将其替换为图像

As you can see on my code, I set Tab1, Tab2, Tab3 as my tab indicators, and want to replace this as an image

这是我的activity_tabhost.xml

This is my activity_tabhost.xml

<TabHost xmlns:android="schemas.android/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@android:id/tabhost"> <LinearLayout android:id="@+id/LinearLayout01" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent"> <TabWidget android:id="@android:id/tabs" android:layout_height="wrap_content" android:layout_width="fill_parent"> </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_height="fill_parent" android:layout_width="fill_parent"> </FrameLayout> </LinearLayout> </TabHost>

推荐答案

在可绘制文件夹的选项卡中添加要使用的图像,然后通过这种方式进行操作.

Add images which you want to use in the tabs in the draw-able folder and get through this way.

tab1.setIndicator("",getResources().getDrawable(R.drawable.tab1)); tab2.setIndicator("",getResources().getDrawable(R.drawable.tab2)); tab3.setIndicator("",getResources().getDrawable(R.drawable.tab3));

更多推荐

如何在Android Tab Host中将图像添加为Tab指示器?

本文发布于:2023-11-15 17:44:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1596613.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指示器   中将   图像   如何在   Host

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!