ActivityGroup实现Tab功能

ActivityGroup实现Tab功能

java文件:

//第一步:初始化各种控件
        layout_myorder_content = (LinearLayout) findViewById(R.id.layout_myorder_content);

        layout_all = (LinearLayout) findViewById(R.id.layout_all);
        layout_goods_to_be_received = (LinearLayout) findViewById(R.id.layout_goods_to_be_received);
        layout_to_be_shipped = (LinearLayout) findViewById(R.id.layout_to_be_shipped);
        layout_to_be_evaluated = (LinearLayout) findViewById(R.id.layout_to_be_evaluated);

        to_be_shipped = (TextView) findViewById(R.id.to_be_shipped);
        all = (TextView) findViewById(R.id.all);
        goods_to_be_received = (TextView) findViewById(R.id.goods_to_be_received);
        to_be_evaluated = (TextView) findViewById(R.id.to_be_evaluated);
        
        layout_all.setOnClickListener(this);
        layout_goods_to_be_received.setOnClickListener(this);
        layout_to_be_shipped.setOnClickListener(this);
        layout_to_be_evaluated.setOnClickListener(this);
         //放在开头,
         all.setTextColor(Color.RED);
        layout_myorder_content.addView(showContentView(0));
//第二步:对layout监控:
@Override
    public void onClick(View v) {
        layout_myorder_content.removeAllViews();
        switch (v.getId()) {
        case R.id.layout_all:
            all.setTextColor(Color.RED);
            to_be_shipped.setTextColor(Color.GRAY);
            goods_to_be_received.setTextColor(Color.GRAY);
            to_be_evaluated.setTextColor(Color.GRAY);
            layout_myorder_content.addView(showContentView(0));
            break;
        case R.id.layout_goods_to_be_received:
            all.setTextColor(Color.GRAY);
            to_be_shipped.setTextColor(Color.GRAY);
            goods_to_be_received.setTextColor(Color.RED);
            to_be_evaluated.setTextColor(Color.GRAY);
            layout_myorder_content.addView(showContentView(2));
            break;
        case R.id.layout_to_be_shipped:
            all.setTextColor(Color.GRAY);
            to_be_shipped.setTextColor(Color.RED);
            goods_to_be_received.setTextColor(Color.GRAY);
            to_be_evaluated.setTextColor(Color.GRAY);
            layout_myorder_content.addView(showContentView(1));
            break;
        case R.id.layout_to_be_evaluated:
            all.setTextColor(Color.GRAY);
            to_be_shipped.setTextColor(Color.GRAY);
            goods_to_be_received.setTextColor(Color.GRAY);
            to_be_evaluated.setTextColor(Color.RED);
            layout_myorder_content.addView(showContentView(3));
            break;

        default:
            break;

//第三步:切换方法showContentView()
private View showContentView(int i) {
        if (i == 0) {
            return getLocalActivityManager()
                    .startActivity(i + " ", new Intent(this, AllActivity.class))
                    .getDecorView();
        } else if (i == 1) {
            return getLocalActivityManager()
                    .startActivity(i + " ", new Intent(this, ShinppedActivity.class))
                    .getDecorView();
        } else if (i == 2) {
            return getLocalActivityManager()
                    .startActivity(i + " ", new Intent(this, ReceivedActivity.class))
                    .getDecorView();
        } else if (i == 3) {
            return getLocalActivityManager()
                    .startActivity(i + " ", new Intent(this, EvaluatedActivity.class))
                    .getDecorView();
        }
        return null;

    }

xml文件:

<include layout="@layout/myorder_header"/>
    //可以是LinearLayout   ,也可以FrameLayout
    <LinearLayout  
        android:id="@+id/layout_myorder_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        />

myorder_header.xml:
 <LinearLayout
        android:id="@+id/layout_all"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <TextView
            android:id="@+id/all"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="全部"
            android:textColor="@color/gray" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout_to_be_shipped"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <TextView
            android:id="@+id/to_be_shipped"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="待发货"
            android:textColor="@color/gray" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout_goods_to_be_received"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <TextView
            android:id="@+id/goods_to_be_received"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="待收货"
            android:textColor="@color/gray" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout_to_be_evaluated"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <TextView
            android:id="@+id/to_be_evaluated"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="待评价"
            android:textColor="@color/gray" />
    </LinearLayout>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值