java - 在 SDK 1.5、API 3 中自定义 TabWidget

标签 java android android-widget

我知道 API 3 不允许为选项卡设置 View ,但我仍然需要修改显示为指示器的 TextView。我还想更改选项卡的 Drawable,但我看不到没有 1.6 API 4 允许的自定义选项卡 View 的方法。

使用下面这个通用示例,有没有办法检索 TextView 并修改其属性或更改可绘制对象?

       TabHost tabHost = getTabHost();
       TabHost.TabSpec spec;

       spec = tabHost.newTabSpec("nearby")
                      .setIndicator("Nearby Activity")
                      .setContent(R.id.nearby_list);                
       tabHost.addTab(spec);        

       spec = tabHost.newTabSpec("friends")
                  .setIndicator("Friends & Favorites")
                      .setContent(R.id.friends_list);
       tabHost.addTab(spec);        

       tabHost.setCurrentTabByTag("nearby");

感谢您的帮助。

最佳答案

改变图标:

 .setIndicator("Friends & Favorites",getResources().getDrawable(R.drawable.myTabIcon))

更改 TabBackground Drawable::

tabHost.getTabWidget().getChildAt( index of tab ).setBackgroundResource(R.drawable.mytab_Newbackground);

要检索 Textview,请检查 Francesco 的示例

ViewGroup v = (ViewGroup) tabHost.getTabWidget().getChildAt( index of tab );
TextView tv = (TextView)v.getChildAt(1); 
Log.d("Tab's text = ",tv.getText().toString());

关于java - 在 SDK 1.5、API 3 中自定义 TabWidget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2981069/

相关文章:

java - 屏蔽字符串时保留空格

java - EditText 焦点和光标选择输入到错误的输入字段

java - 无法启动 Eclipse Helios

android - 如何动画隐藏 View 的过程?

android - 在 Android 3 中使用 NumberPicker

java - ThreadPoolExecutor 的运行永远不会超过池大小

android - MaterialCardView 没有波纹

android - 在android中获取联系人非常慢

android - 空 ViewPager 使用 PagerTabStrip 崩溃

android - 如何以粗体样式设置自定义字体