二月最后一天的总结

今天找网友面基了,对方浓度过高导致我差点招架不住,正常存活,也算是多了一个朋友

导致今天没学多少东西,不过收获还是有一点点的。

首先是自己用原生的控件写了一个导航,具体如下所示:

 

能实现点击和滑动的跳转

使用到的技术有基本的布局和控件、矢量图、selector、Fragment、FragmentPagerAdapter、和Activity的结合

具体代码先放一点点吧

package com.example.fragment.nevigation1;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.viewpager.widget.ViewPager;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.fragment.R;

public class Nevigation1Activity extends AppCompatActivity {
    private LinearLayout ll_home,ll_find,ll_mine;
    private ImageView iv_home,iv_find,iv_mine;
    private TextView tv_home,tv_find,tv_mine;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_nevigation1);


        ll_home = findViewById(R.id.ll_home);
        ll_find = findViewById(R.id.ll_find);
        ll_mine = findViewById(R.id.ll_mine);

        iv_home = findViewById(R.id.iv_home);
        iv_find = findViewById(R.id.iv_find);
        iv_mine = findViewById(R.id.iv_mine);

        tv_home = findViewById(R.id.tv_home);
        tv_find = findViewById(R.id.tv_find);
        tv_mine = findViewById(R.id.tv_mine);

        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        BlankFragment fragment = BlankFragment.newInstance("这是首页","");
        iv_home.setSelected(true);
        tv_home.setTextColor(Color.GREEN);
        transaction.replace(R.id.fcv,fragment).commit();
        ll_home.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FragmentManager manager = getSupportFragmentManager();
                FragmentTransaction transaction = manager.beginTransaction();
                BlankFragment fragment = BlankFragment.newInstance("这是首页","");
                iv_home.setSelected(true);
                tv_home.setTextColor(Color.GREEN);

                iv_find.setSelected(false);
                tv_find.setTextColor(Color.GRAY);

                iv_mine.setSelected(false);
                tv_mine.setTextColor(Color.GRAY);

                transaction.replace(R.id.fcv,fragment).commit();
            }
        });
        ll_find.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FragmentManager manager = getSupportFragmentManager();
                FragmentTransaction transaction = manager.beginTransaction();
                BlankFragment fragment = BlankFragment.newInstance("这是发现页","");
                iv_home.setSelected(false);
                tv_home.setTextColor(Color.GRAY);

                iv_find.setSelected(true);
                tv_find.setTextColor(Color.GREEN);

                iv_mine.setSelected(false);
                tv_mine.setTextColor(Color.GRAY);
                transaction.replace(R.id.fcv,fragment).commit();
            }
        });
        ll_mine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FragmentManager manager = getSupportFragmentManager();
                FragmentTransaction transaction = manager.beginTransaction();
                BlankFragment fragment = BlankFragment.newInstance("这是我的页","");
                iv_home.setSelected(false);
                tv_home.setTextColor(Color.GRAY);

                iv_find.setSelected(false);
                tv_find.setTextColor(Color.GRAY);

                iv_mine.setSelected(true);
                tv_mine.setTextColor(Color.GREEN);
                transaction.replace(R.id.fcv,fragment).commit();
            }
        });
    }
}

 

posted @ 2023-02-28 23:19  -她的梦-  阅读(14)  评论(0编辑  收藏  举报