Android 底部导航栏实现

依赖库

    implementation "androidx.viewpager2:viewpager2:1.0.0"

fragment基类 


/*** Fragment的基类** @param <DB> data binding* @param <VM> view model* @author shizhiyin*/
public abstract class BaseFragment<DB extends ViewDataBinding, VM extends BaseViewModel>extends Fragment {protected DB mDataBinding;protected VM mViewModel;private FragmentBaseBinding mFragmentBaseBinding;private ViewLoadingBinding mViewLoadingBinding;private ViewLoadErrorBinding mViewLoadErrorBinding;private ViewNoNetworkBinding mViewNoNetworkBinding;private ViewNoDataBinding mViewNoDataBinding;@Overridepublic void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);Bundle args = getArguments();if (args != null) {handleArguments(args);}initViewModel();// ViewModel订阅生命周期事件if (mViewModel != null) {getLifecycle().addObserver(mViewModel);}}@Nullable@Overridepublic View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {mFragmentBaseBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_base, container, false);mDataBinding = DataBindingUtil.inflate(inflater, getLayoutResId(),mFragmentBaseBinding.flContentContainer, true);bindViewModel();mDataBinding.setLifecycleOwner(this);initLoadState();initCollectState();init();return mFragmentBaseBinding.getRoot();}private void initLoadState() {if (mViewModel != null && isSupportLoad()) {mViewModel.loadState.observe(getViewLifecycleOwner(), new Observer<LoadState>() {@Overridepublic void onChanged(LoadState loadState) {switchLoadView(loadState);}});}}/*** 根据加载状态 , 切换不同的View** @param loadState*/private void switchLoadView(LoadState loadState) {removeLoadView();switch (loadState) {case LOADING:if (mViewLoadingBinding == null) {mViewLoadingBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.view_loading,mFragmentBaseBinding.flContentContainer, false);}mFragmentBaseBinding.flContentContainer.addView(mViewLoadingBinding.getRoot());break;case NO_NETWORK:if (mViewNoNetworkBinding == null) {mViewNoNetworkBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.view_no_network,mFragmentBaseBinding.flContentContainer, false);mViewNoNetworkBinding.setViewModel(mViewModel);}mFragmentBaseBinding.flContentContainer.addView(mViewNoNetworkBinding.getRoot());break;case NO_DATA:if (mViewNoDataBinding == null) {mViewNoDataBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.view_no_data,mFragmentBaseBinding.flContentContainer, false);}mFragmentBaseBinding.flContentContainer.addView(mViewNoDataBinding.getRoot());break;case ERROR:if (mViewLoadErrorBinding == null) {mViewLoadErrorBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.view_load_error,mFragmentBaseBinding.flContentContainer, false);mViewLoadErrorBinding.setViewModel(mViewModel);}mFragmentBaseBinding.flContentContainer.addView(mViewLoadErrorBinding.getRoot());break;default:break;}}private void removeLoadView() {int childCount = mFragmentBaseBinding.flContentContainer.getChildCount();if (childCount > 1) {mFragmentBaseBinding.flContentContainer.removeViews(1, childCount - 1);}}@SuppressLint("FragmentLiveDataObserve")private void initCollectState() {if (mViewModel == null) {return;}mViewModel.getCollectStatus().observe(this, new Observer<Object>() {@Overridepublic void onChanged(Object collect) {if (collect == null) {//跳转到登录界面LoginActivity.start(getActivity());}}});}@Overridepublic void onDestroyView() {super.onDestroyView();// ViewModel订阅生命周期事件if (mViewModel != null) {getLifecycle().removeObserver(mViewModel);}removeLoadView();}/*** 处理参数** @param args 参数容器*/protected void handleArguments(Bundle args) {}/*** 是否支持页面加载。默认不支持** @return true表示支持,false表示不支持*/protected boolean isSupportLoad() {return false;}/*** 获取当前页面的布局资源ID** @return 布局资源ID*/protected abstract int getLayoutResId();/*** 初始化ViewModel*/protected abstract void initViewModel();/*** 绑定ViewModel*/protected abstract void bindViewModel();/*** 初始化*/protected abstract void init();
}

baseActivity


/*** Activity的基类** @param <DB> data binding* @param <VM> view model* @author shizhiyin*/
public abstract class BaseActivity<DB extends ViewDataBinding, VM extends BaseViewModel>extends AppCompatActivity {public DB mDataBinding;protected VM mViewModel;private ActivityBaseBinding mActivityBaseBinding;private ViewLoadingBinding mViewLoadingBinding;private ViewLoadErrorBinding mViewLoadErrorBinding;private ViewNoNetworkBinding mViewNoNetworkBinding;private ViewNoDataBinding mViewNoDataBinding;private BatteryReceiver receiver;@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);handleIntent(getIntent());if (isNoActionBar()) {setNoActionBar();}mActivityBaseBinding = DataBindingUtil.setContentView(this, R.layout.activity_base);mDataBinding = DataBindingUtil.inflate(getLayoutInflater(), getLayoutResId(),mActivityBaseBinding.flContentContainer, true);initViewModel();bindViewModel();mDataBinding.setLifecycleOwner(this);initLoadState();init();//注册设备电池监听广播receiver = new BatteryReceiver() {@Overridepublic void onReceive(Context context, Intent intent) {super.onReceive(context, intent);BatteryManager batteryManager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);int batteryLevel = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
//                int battery = batteryManager.getIntProperty(BatteryManager.BATTERY_STATUS_CHARGING);int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {boolean isCharging = false;if (status == 2) {isCharging = true;}handtBatteryData(batteryLevel, isCharging);}//wifi监测Boolean isWifiConnected = isNetworkAvailable(context);if (!isWifiConnected) {//没连网络handtWifiData(false, 1);} else {//已连网络handtWifiData(true, 2);}}};IntentFilter filter2 = new IntentFilter();filter2.addAction(Intent.ACTION_BATTERY_CHANGED);registerReceiver(receiver, filter2);// ViewModel订阅生命周期事件if (mViewModel != null) {getLifecycle().addObserver(mViewModel);}}/*** 设置沉浸式状态栏*/private void setNoActionBar() {Window window = getWindow();View decorView = window.getDecorView();int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;decorView.setSystemUiVisibility(option);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);window.setStatusBarColor(Color.TRANSPARENT);}}private void initLoadState() {if (mViewModel != null && isSupportLoad()) {mViewModel.loadState.observe(this, new Observer<LoadState>() {@Overridepublic void onChanged(LoadState loadState) {switchLoadView(loadState);}});}}private void removeLoadView() {int childCount = mActivityBaseBinding.flContentContainer.getChildCount();if (childCount > 1) {mActivityBaseBinding.flContentContainer.removeViews(1, childCount - 1);}}private void switchLoadView(LoadState loadState) {removeLoadView();switch (loadState) {case LOADING:if (mViewLoadingBinding == null) {mViewLoadingBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.view_loading,mActivityBaseBinding.flContentContainer, false);}mActivityBaseBinding.flContentContainer.addView(mViewLoadingBinding.getRoot());break;case NO_NETWORK:if (mViewNoNetworkBinding == null) {mViewNoNetworkBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.view_no_network,mActivityBaseBinding.flContentContainer, false);mViewNoNetworkBinding.setViewModel(mViewModel);}mActivityBaseBinding.flContentContainer.addView(mViewNoNetworkBinding.getRoot());break;case NO_DATA:if (mViewNoDataBinding == null) {mViewNoDataBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.view_no_data,mActivityBaseBinding.flContentContainer, false);}mActivityBaseBinding.flContentContainer.addView(mViewNoDataBinding.getRoot());break;case ERROR:if (mViewLoadErrorBinding == null) {mViewLoadErrorBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.view_load_error,mActivityBaseBinding.flContentContainer, false);}mActivityBaseBinding.flContentContainer.addView(mViewLoadErrorBinding.getRoot());break;default:break;}}@Overrideprotected void onDestroy() {super.onDestroy();unregisterReceiver(receiver);}/*** 电池* 连接状态*/protected void handtBatteryData(int batteryLevel, boolean isCharging) {}/*** wifi* 连接状态*/protected void handtWifiData(boolean isConnected, int level) {}/*** 处理参数** @param intent 参数容器*/protected void handleIntent(Intent intent) {}/*** 是否为沉浸模式** @return true表示支持,false表示不支持*/protected boolean isNoActionBar() {return false;}/*** 是否支持页面加载。默认不支持** @return true表示支持,false表示不支持*/protected boolean isSupportLoad() {return false;}/*** 获取当前页面的布局资源ID** @return 布局资源ID*/protected abstract int getLayoutResId();/*** 初始化ViewModel*/protected abstract void initViewModel();/*** 绑定ViewModel*/protected abstract void bindViewModel();/*** 初始化*/protected abstract void init();}

一、Fragment + TextView 实现

1、主界面


/*** 主界面*/
public class MainActivity extends BaseActivity<ActivityMainBinding, MainViewModel> {public static void start(Context context, Boolean isLogin) {Intent intent = new Intent(context, MainActivity.class);intent.putExtra(Constants.ParamCode.PARAM1, isLogin);context.startActivity(intent);}@Overrideprotected void handleIntent(Intent intent) {}@Overrideprotected void onNewIntent(Intent intent) {super.onNewIntent(intent);}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);}@Overrideprotected int getLayoutResId() {return R.layout.activity_main;}@Overrideprotected void initViewModel() {mViewModel = new ViewModelProvider(this).get(MainViewModel.class);}@Overrideprotected void bindViewModel() {}private List<Fragment> fragmentList;private ContentPagerAdapter contentPagerAdapter;@Overrideprotected void init() {initView();fragmentList = new ArrayList<>();fragmentList.add(new HomeFragment());fragmentList.add(new ShoppingFragment());fragmentList.add(new LifeServicesFragment());fragmentList.add(new EduStewarFragment());fragmentList.add(new PersonCenterFragment());contentPagerAdapter = new ContentPagerAdapter(this, fragmentList);mDataBinding.viewPager.setAdapter(contentPagerAdapter);mDataBinding.textViewHome.setOnClickListener(v -> mDataBinding.viewPager.setCurrentItem(0, false));mDataBinding.textViewShopping.setOnClickListener(v -> mDataBinding.viewPager.setCurrentItem(1, false));mDataBinding.textViewLifeServices.setOnClickListener(v -> mDataBinding.viewPager.setCurrentItem(2, false));mDataBinding.textviewEduStewar.setOnClickListener(v -> mDataBinding.viewPager.setCurrentItem(3, false));mDataBinding.textviewPersonCenter.setOnClickListener(v -> mDataBinding.viewPager.setCurrentItem(4, false));mDataBinding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {@Overridepublic void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {// 当页面滑动时调用super.onPageScrolled(position, positionOffset, positionOffsetPixels);changeState(position);}@Overridepublic void onPageSelected(int position) {// 当页面被选中时调用super.onPageSelected(position);}@Overridepublic void onPageScrollStateChanged(int state) {// 当页面滑动状态改变时调用super.onPageScrollStateChanged(state);}});}/*** 改变* 导航栏样式*/private void changeState(int position) {mDataBinding.textViewHome.setTextColor(Color.parseColor("#93A5EE"));mDataBinding.textViewShopping.setTextColor(Color.parseColor("#93A5EE"));mDataBinding.textViewLifeServices.setTextColor(Color.parseColor("#93A5EE"));mDataBinding.textviewEduStewar.setTextColor(Color.parseColor("#93A5EE"));mDataBinding.textviewPersonCenter.setTextColor(Color.parseColor("#93A5EE"));switch (position) {case 0:mDataBinding.textViewHome.setTextColor(Color.parseColor("#52FDFF"));break;case 1:mDataBinding.textViewShopping.setTextColor(Color.parseColor("#52FDFF"));break;case 2:mDataBinding.textViewLifeServices.setTextColor(Color.parseColor("#52FDFF"));break;case 3:mDataBinding.textviewEduStewar.setTextColor(Color.parseColor("#52FDFF"));break;case 4:mDataBinding.textviewPersonCenter.setTextColor(Color.parseColor("#52FDFF"));break;default:mDataBinding.textViewHome.setTextColor(Color.parseColor("#52FDFF"));break;}}@Overrideprotected void onResume() {super.onResume();}/*** 初始view*/private void initView() {}@Overridepublic void onBackPressed() {
//        super.onBackPressed();}
}

2、xml布局

<layout 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"><data></data><androidx.constraintlayout.widget.ConstraintLayoutandroid:layout_width="@dimen/dp_640"android:layout_height="@dimen/dp_400"><androidx.viewpager2.widget.ViewPager2android:id="@+id/viewPager"android:layout_width="@dimen/dp_640"android:layout_height="350dp"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /><LinearLayoutandroid:id="@+id/bottom_navigation"android:layout_width="0dp"android:layout_height="50dp"android:background="#00064F"android:orientation="horizontal"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"><TextViewandroid:id="@+id/textViewHome"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:clickable="true"android:focusable="true"android:gravity="center"android:text="首页"android:textColor="#52FDFF"android:textSize="@dimen/sp_10" /></LinearLayout><TextViewandroid:id="@+id/textViewShopping"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:clickable="true"android:focusable="true"android:gravity="center"android:text="商城"android:textColor="#52FDFF"android:textSize="@dimen/sp_10" /><TextViewandroid:id="@+id/textViewLifeServices"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:clickable="true"android:focusable="true"android:gravity="center"android:text="服务"android:textColor="#52FDFF"android:textSize="@dimen/sp_10" /><TextViewandroid:id="@+id/textviewEduStewar"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:clickable="true"android:focusable="true"android:gravity="center"android:text="管家"android:textColor="#52FDFF"android:textSize="@dimen/sp_10" /><TextViewandroid:id="@+id/textviewPersonCenter"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:clickable="true"android:focusable="true"android:gravity="center"android:text="个人"android:textColor="#52FDFF"android:textSize="@dimen/sp_10" /></LinearLayout></androidx.constraintlayout.widget.ConstraintLayout>
</layout>

3、首页

3.1 fragment代码

public class HomeFragment extends BaseFragment<HomeFragmentLayoutBinding,HomeFragmentViewmodel> {@Overrideprotected int getLayoutResId() {return R.layout.home_fragment_layout;}@Overrideprotected void initViewModel() {}@Overrideprotected void bindViewModel() {}@Overrideprotected void init() {}
}

3.2 布局代码

<?xml version="1.0" encoding="utf-8"?>
<layout 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"><data></data><androidx.constraintlayout.widget.ConstraintLayoutandroid:layout_width="@dimen/dp_640"android:layout_height="@dimen/dp_400"android:background="@color/color_red"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="首页"android:textColor="@color/white"android:textSize="@dimen/sp_16"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /></androidx.constraintlayout.widget.ConstraintLayout>
</layout>

4、商场页面

4.1fragment代码

public class ShoppingFragment extends BaseFragment<ShoppingFragmentLayoutBinding, ShoppingFragmentViewModel> {@Overrideprotected int getLayoutResId() {return R.layout.shopping_fragment_layout;}@Overrideprotected void initViewModel() {}@Overrideprotected void bindViewModel() {}@Overrideprotected void init() {}}

4.2布局代码

<?xml version="1.0" encoding="utf-8"?>
<layout 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"><data></data><androidx.constraintlayout.widget.ConstraintLayoutandroid:layout_width="@dimen/dp_640"android:layout_height="@dimen/dp_400"android:background="@color/green"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="小雅购物"android:textColor="@color/white"android:textSize="@dimen/sp_16"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /></androidx.constraintlayout.widget.ConstraintLayout>
</layout>

5、服务页面

5.1服务fragment


public class LifeServicesFragment extends BaseFragment<LifeServicesFragmentLayoutBinding, LifeServicesFragmentViewmodel> {@Overrideprotected int getLayoutResId() {return R.layout.life_services_fragment_layout;}@Overrideprotected void initViewModel() {}@Overrideprotected void bindViewModel() {}@Overrideprotected void init() {}}

5.2服务布局页面

<?xml version="1.0" encoding="utf-8"?>
<layout 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"><data></data><androidx.constraintlayout.widget.ConstraintLayoutandroid:layout_width="@dimen/dp_640"android:layout_height="@dimen/dp_400"android:background="@color/color_red"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="生活服务"android:textColor="@color/white"android:textSize="@dimen/sp_16"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /></androidx.constraintlayout.widget.ConstraintLayout>
</layout>

6、教育页面

6.1教育fragment代码


/*** 教育管家*/
public class EduStewarFragment extends BaseFragment<EduStewarFragmentLayoutBinding, EduStewarFragmentViewmodel> {@Overrideprotected int getLayoutResId() {return R.layout.edu_stewar_fragment_layout;}@Overrideprotected void initViewModel() {}@Overrideprotected void bindViewModel() {}@Overrideprotected void init() {}}

6.2教育布局代码

<?xml version="1.0" encoding="utf-8"?>
<layout 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"><data></data><androidx.constraintlayout.widget.ConstraintLayoutandroid:layout_width="@dimen/dp_640"android:layout_height="@dimen/dp_400"android:background="@color/color_red"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="教育管家"android:textColor="@color/white"android:textSize="@dimen/sp_16"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /></androidx.constraintlayout.widget.ConstraintLayout>
</layout>

7、个人中心

7.1个人中心fragment

public class PersonCenterFragment extends BaseFragment<PersonCenterBinding,PersonCenterVieMOdel> {@Overrideprotected int getLayoutResId() {return R.layout.person_center;}@Overrideprotected void initViewModel() {}@Overrideprotected void bindViewModel() {}@Overrideprotected void init() {}
}

7.2个人中心布局页面

<?xml version="1.0" encoding="utf-8"?>
<layout 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"><data></data><androidx.constraintlayout.widget.ConstraintLayoutandroid:layout_width="@dimen/dp_640"android:layout_height="@dimen/dp_400"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="个人中心"android:textColor="@color/black"android:textSize="@dimen/sp_16"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent"  /></androidx.constraintlayout.widget.ConstraintLayout>
</layout>

二、RadioGroup + ViewPager 实现

三、BottomNavigationView+ViewPager+fragment 实现

四、TabLayout+fragment+viewPager 实现

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/47174.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

线程控制

对线程的控制思路和进程相似&#xff0c;创建、等待、终止&#xff0c;只需要调用接口就行。但是在Linux下没有线程的概念&#xff0c;因为Linux的设计者认为&#xff0c;线程是一种轻量级的进程&#xff0c;毕竟创建线程只需要创建PCB。因此Linux中使用多线程必须使用第三方pt…

Spring MVC入门2

Postman的使用 接上期我们抛出了一个问题&#xff0c;Postman的使用 可以点击链接下载 https://www.postman.com/downloads/ 安装之后会提示版本升级&#xff0c;直接点击dissmiss即可。 要想发送数据&#xff0c;具体歩奏如下简图&#xff1a; 还有一个更具体的图&#xff…

使用GDAL(C++库)从末尾行开始向上读取图像数据

使用GDAL&#xff08;C库&#xff09;从末尾行读取图像数据 OpenCV等图像库默认的读取方式都是从第一行开始&#xff0c;逐行读取数据&#xff08;自顶向下&#xff09;&#xff0c;填充到内存缓冲区&#xff1b;对于某些特殊应用&#xff0c;需要反行序读取&#xff08;从末尾…

朴素模式匹配算法与KMP算法(非重点)

目录 一. 朴素模式匹配算法1.1 什么是字符串的匹配模式1.2 朴素模式匹配算法1.3 通过数组下标实现朴素模式匹配算法 二. KMP算法2.1 算法分析2.2 用代码实现&#xff08;只会出现在选择题&#xff0c;考察代码的概率不大&#xff09; 三. 手算next数组四. KMP算法的进一步优化4…

Python + Playwright(21):拦截网络请求

Python + Playwright(21):拦截网络请求 前言什么是路由(Route)?使用示例基础拦截配置使用正则表达式模式自定义处理函数注意事项总结前言 在进行自动化测试,当网页加载时,我们经常会遇到页面上存在大量非核心内容,这些内容可能并不直接影响我们的测试目标。为了优化加…

新手学习AIGC的步骤与图谱

学习人工智能和生成式对话模型&#xff08;Artificial Intelligence and Generative Conversational Models&#xff09;是一项令人兴奋且具有挑战性的任务&#xff01;以下是一些我认为可行的学习步骤和路径&#xff1a; 初学者学习AIGC的步骤&#xff1a; 掌握基础知识&#…

在AWS创建一台Windows主机并登录

正文共&#xff1a;1111 字 21 图&#xff0c;预估阅读时间&#xff1a;1 分钟 因为之前微软云Azure免费&#xff0c;我们还做了简单的测试&#xff08;白嫖党618福利&#xff01;来Azure领200美刀&#xff01;外加云主机免费用一年&#xff01;&#xff09;&#xff1b;并且通…

k8s核心操作_存储抽象_K8S中使用Secret功能来存储密码_使用免密拉取镜像_k8s核心实战总结---分布式云原生部署架构搭建033

注意在看的时候一定要把 dxxxx中的xxxx换成--o----c----k----e----r 然后我们再来看一个k8s中的secret的功能,这个功能 用来存储密码的,configMap是用来存配置的 比如我们有个pod,他的镜像,如果是需要密码的,那么 我们现在是从公共仓库拉取的,如果我们从私有仓库拉取,有密码…

Github 2024-07-13 Rust开源项目日报 Top10

根据Github Trendings的统计,今日(2024-07-13统计)共有10个项目上榜。根据开发语言中项目的数量,汇总情况如下: 开发语言项目数量Rust项目10C项目1Zed: 由Atom和Tree-sitter的创建者开发的高性能多人代码编辑器 创建周期:1071 天开发语言:Rust协议类型:OtherStar数量:94…

python 请求https api, header参数的设置

在Python中发送HTTPS请求并设置header参数&#xff0c;可以使用requests库。requests库是一个方便发送HTTP请求的第三方库&#xff0c;支持发送GET、POST等请求&#xff0c;同时还支持设置header参数。 首先&#xff0c;确保你已经安装了requests库&#xff0c;可以使用以下命…

从 Icelake 到 Iceberg Rust

本文作者丁皓是Databend 研发工程师&#xff0c;也是 ASF Member&#xff0c; Apache OpenDAL PMC Chair &#xff0c;主要研究领域包括存储、自动化与开源。 太长不看 Icelake 已经停止更新&#xff0c;请改用 iceberg-rust。 Iceberg-rust 是一个由社区驱动的项目&#xff0…

自动化创建 AWS RDS 实例告警

在管理 AWS RDS 数据库实例时,设置适当的监控和告警是至关重要的。本文将介绍如何使用 Python 和 AWS SDK (boto3) 自动化创建 RDS 实例的 CloudWatch 告警。 背景 对于大规模的 RDS 部署,手动为每个实例创建告警既耗时又容易出错。通过自动化这个过程,我们可以确保所有符…

《0基础》学习Python——第十六讲

《文件读写》 一、什么是文件读写 文件读写是指在Python程序中对文件进行读取和写入操作。通过文件读写&#xff0c;可以读取文件中的数据&#xff0c;或者向文件中写入数据。 Python提供了多种文件读写的方式&#xff0c;其中最常用的方式是使用open()函数打开一个文件&#…

深入理解Android中的缓存与文件存储目录

&#x1f31f; 引言 在Android应用开发中&#xff0c;合理管理应用的数据存储至关重要。应用可能需要保存各种类型的数据&#xff0c;从简单的配置信息到多媒体文件&#xff0c;甚至是缓存数据以提高性能和用户体验。Android提供了多个内置目录来满足这些需求&#xff0c;但它…

kubernetes集群环境搭建(二)

kubernetes集群类型 kubernetes集群大体上分为两类&#xff1a;一主多从和多主多从 一主多从&#xff1a;一台Master节点和多台Node节点&#xff0c;搭建简单&#xff0c;但有单机故障风险&#xff0c;适合于测试环境部署多主多从&#xff1a;多台Matser节点和多台Node节点&…

MyBatis的原理?

MyBatis是一个优秀的持久层框架&#xff0c;它支持定制化SQL、存储过程以及高级映射。MyBatis避免了几乎所有的JDBC代码和手动设置参数及获取结果集。MyBatis可以通过简单的XML或注解来配置和映射原生类型、接口和Java的POJOs&#xff08;Plain Old Java Objects&#xff09;为…

linux中导出sql脚本

linux中导出sql脚本 前言&#xff1a; 需要将数据库xx表导出sql脚本、数据迁移、数据备份… 执行命令 1. 导出整个数据库的数据 -- username: 是数据库的用户名 -- database_name: 是要导出数据的数据库名 -- dump_file.sql: 是导出的 SQL 文件名&#xff0c;你可以自己定义…

策略模式原理与C++实现

定义 定义一些列算法&#xff0c;把他们一个个封装起来&#xff0c;并且使他们可以相互替换&#xff08;变化&#xff09;。该模式使得算法可独立于使用它的客户程序&#xff08;稳定&#xff09;而变化&#xff08;扩展、子类化&#xff09;。 C实现 在不考虑策略模式的情况…

js基础-小数计算,并转换成带两位的百分比

小数计算&#xff0c;并转换成带两位的百分比 1、需求说明2、执行过程2.1 计算 s12.2 计算 s2 1、需求说明 在工作中&#xff0c;有时需要将计算的小数转换成百分比小数&#xff0c;但是在js代码中&#xff0c;计算公式一点点的区别就会影响到最终的结果&#xff0c;如下面代码…

vue视频、图片自动轮播并伴随进度条

废话不多说直接上代 多余没用的部分自己看着删除 <template><div class"showImg"><el-carousel ref"carousel" trigger"hover" :autoplay"false" class"dimControl" :height"${(currenInnerWith*0.37…