导航栏

Mainctivity

package com.example.a01380913.ccss;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


public class MainActivity extends AppCompatActivity {

    LinearLayout line1,line2,line3,line4;
    TextView text1,text2,text3,text4;
    ImageView image1,image2,image3,image4;
    private F1 f1;
    private F2 f2;
    private F3 f3;
    private F4 f4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        line1=findViewById(R.id.line1);
        line2=findViewById(R.id.line2);
        line3=findViewById(R.id.line3);
        line4=findViewById(R.id.line4);
        text1=findViewById(R.id.text1);
        text2=findViewById(R.id.text2);
        text3=findViewById(R.id.text3);
        text4=findViewById(R.id.text4);
        image1=findViewById(R.id.image1);
        image2=findViewById(R.id.image2);
        image3=findViewById(R.id.image3);
        image4=findViewById(R.id.image4);
        f1 = new F1();
        f2 = new F2();
        f3 = new F3();
        f4 = new F4();

        getSupportFragmentManager().beginTransaction().replace(R.id.bj,f1).commit();
        text1.setTextColor(Color.RED);
        text2.setTextColor(Color.BLACK);
        text3.setTextColor(Color.BLACK);
        text4.setTextColor(Color.BLACK);
        image1.setImageResource(R.mipmap.icon_choose_light);
        image2.setImageResource(R.mipmap.ic_launcher);
        image3.setImageResource(R.mipmap.ic_launcher);
        image4.setImageResource(R.mipmap.ic_launcher);

        line1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportFragmentManager().beginTransaction().replace(R.id.bj,f1).commit();
                text1.setTextColor(Color.RED);
                text2.setTextColor(Color.BLACK);
                text3.setTextColor(Color.BLACK);
                text4.setTextColor(Color.BLACK);
                image1.setImageResource(R.mipmap.icon_choose_light);
                image2.setImageResource(R.mipmap.ic_launcher);
                image3.setImageResource(R.mipmap.ic_launcher);
                image4.setImageResource(R.mipmap.ic_launcher);

            }
        });

        line2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportFragmentManager().beginTransaction().replace(R.id.bj,f2).commit();
                text2.setTextColor(Color.RED);
                text1.setTextColor(Color.BLACK);
                text3.setTextColor(Color.BLACK);
                text4.setTextColor(Color.BLACK);
                image2.setImageResource(R.mipmap.icon_choose_light);
                image1.setImageResource(R.mipmap.ic_launcher);
                image3.setImageResource(R.mipmap.ic_launcher);
                image4.setImageResource(R.mipmap.ic_launcher);
            }
        });

        line3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportFragmentManager().beginTransaction().replace(R.id.bj,f3).commit();
                text3.setTextColor(Color.RED);
                text2.setTextColor(Color.BLACK);
                text1.setTextColor(Color.BLACK);
                text4.setTextColor(Color.BLACK);
                image3.setImageResource(R.mipmap.icon_choose_light);
                image2.setImageResource(R.mipmap.ic_launcher);
                image1.setImageResource(R.mipmap.ic_launcher);
                image4.setImageResource(R.mipmap.ic_launcher);
            }
        });

        line4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportFragmentManager().beginTransaction().replace(R.id.bj,f4).commit();
                text4.setTextColor(Color.RED);
                text2.setTextColor(Color.BLACK);
                text3.setTextColor(Color.BLACK);
                text1.setTextColor(Color.BLACK);
                image4.setImageResource(R.mipmap.icon_choose_light);
                image2.setImageResource(R.mipmap.ic_launcher);
                image3.setImageResource(R.mipmap.ic_launcher);
                image1.setImageResource(R.mipmap.ic_launcher);
            }
        });

    }
}

———————————————————————————————————————————————————————

xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".Main2Activity">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:id="@+id/bj"
        ></FrameLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="8"
        >

        <LinearLayout
            android:id="@+id/line1"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_marginTop="5dp"
            >

            <ImageView
                android:id="@+id/image1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:src="@mipmap/ic_launcher"
                />

            <TextView
                android:id="@+id/text1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:text="首页"
                android:textColor="#000"
                android:gravity="center"
                />


        </LinearLayout>
        <LinearLayout
            android:id="@+id/line2"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_marginTop="5dp"
            >
            <ImageView
                android:id="@+id/image2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:src="@mipmap/ic_launcher"
                />

            <TextView
                android:id="@+id/text2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:text="分类"
                android:textColor="#000"
                android:gravity="center"
                />
        </LinearLayout>
        <LinearLayout
            android:id="@+id/line3"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_marginTop="5dp"
            >
            <ImageView
                android:id="@+id/image3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:src="@mipmap/ic_launcher"
                />

            <TextView
                android:id="@+id/text3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:text="购物车"
                android:textColor="#000"
                android:gravity="center"
                />
        </LinearLayout>
        <LinearLayout
            android:id="@+id/line4"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_marginTop="5dp"
            >
            <ImageView
                android:id="@+id/image4"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:src="@mipmap/ic_launcher"
                />

            <TextView
                android:id="@+id/text4"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:text="我的"
                android:textColor="#000"
                android:gravity="center"
                />
        </LinearLayout>



    </LinearLayout>


</LinearLayout>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值