android中很多时候,默认的TAB样式并不好看,我们能不能编写XML对其样式进行修改。修改成 下图中的现需:按上图中的,自定义样式的TAB布局例子 thanks

解决方案 »

  1.   

    编写xml可能比较难吧,直接继承类,在tabhost基础上自己画
      

  2.   

    3楼的,
    你的资源,我下载不了,你能用email发给我吗?thanks
    我的email:   [email protected]
      

  3.   

    多谢 5楼的,
    再问3楼和5楼:<?xml version="1.0" encoding="UTF-8"?>
    <selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
    android:state_focused="false"
    android:state_selected="false"
    android:state_pressed="false"
    android:drawable="@drawable/tab_unselected" />
    <item
    android:state_focused="false"
    android:state_selected="true"
    android:state_pressed="false"
    android:drawable="@drawable/onselect"  />
    <item
    android:state_focused="true"
    android:state_selected="false"
    android:state_pressed="false"
    android:drawable="@drawable/onselect"  />
    <item
    android:state_focused="true"
    android:state_selected="true"
    android:state_pressed="false"
    android:drawable="@drawable/onselect"  />
    <item
    android:state_pressed="true"
    android:drawable="@drawable/onselect"  />
    </selector>1 这个xml是用来设置,选中某选项时,会跟上一背景图,对吗
    2 现如果要在选中某选项时,还要再把选中项的文字的颜色变成红色,怎么实现呀
    thanks
      

  4.   

    一个tabhost + selector  搞定
      

  5.   

    7楼的能说的详细点吗,
    是在6楼提到的selector中写程序吗?还是?
      

  6.   

    public class TestTabHostActivity extends TabActivity {
        
    private TabWidget tabWidget;
    Resources res;
        TabHost tabHost;
        TabHost.TabSpec spec;
        Intent intent;
        
        public void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState); 
            setContentView(R.layout.main);
            makeTab();
            processTab();
            
        }
      

  7.   

    private void processTab() {
    tabWidget = (TabWidget) findViewById(android.R.id.tabs);

    for (int i = 0; i < tabWidget.getChildCount(); i++) {
    final TextView textView = (TextView) tabWidget.getChildAt(i).findViewById(R.id.tabtext);
    textView.setTextColor(Color.BLUE);
    }
    }
      

  8.   

    private void makeTab() {
    res = getResources();
    tabHost = getTabHost();

    View tabView = View.inflate(this, R.layout.tab_view, null);
    ImageView imageView = (ImageView) tabView.findViewById(R.id.tabimage);
    imageView.setImageResource(R.drawable.e010);
    TextView textView = (TextView) tabView.findViewById(R.id.tabtext);
    textView.setText("我不懂");

            intent = new Intent().setClass(this, TestCalendarActivity.class);
            spec = tabHost.newTabSpec("first").setIndicator(tabView)
                .setContent(intent);
            tabHost.addTab(spec);
      

  9.   


    对啊,tabhost是一个布局  里面可以放这些:头条,都市。等等
    但是这个头条按下的效果,非按下的效果可以在selector中实现至于头条对应的内容,就需要额外一个布局了 ,扯远了  。有点晕温馨提示:LZ可以结贴了
      

  10.   

    多谢,问题已解决
    public void onTabChanged(String tabId) {
    //tabId值为要切换到的tab页的索引位置
    int tabID = Integer.valueOf(tabId);
    for (int i = 0; i < tabWidget.getChildCount(); i++)
    {
    if (i == tabID) 
    {
    tabWidget.getChildAt(Integer.valueOf(i));
    final TextView textView = (TextView) tabWidget.getChildAt(Integer.valueOf(i)).findViewById(R.id.title);
    textView.setTextColor(0xffFEFFFF);

    else 
    {
    tabWidget.getChildAt(Integer.valueOf(i));
    final TextView textView = (TextView) tabWidget.getChildAt(Integer.valueOf(i)).findViewById(R.id.title);
    textView.setTextColor(0xff767674);
    }
    }
    }