1. 根据创建 navigation 类型项目

1.	Android主页设计步骤

    1. 创建layout

在res/layout目录节点上“右键”->New->XML->layout XML file.命名布局方名为fr_settings,root tag设置为ContraintLayout

1.	Android主页设计步骤

    1. 生成的布局文件为:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent">

</androidx.constraintlayout.widget.ConstraintLayout>

 

 

创建Fragment类

新建类settings,基类为Fragment:

1.	Android主页设计步骤

加入构造函数:

package com.hhiot.hhvideo.ui.settings;



import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;



import androidx.annotation.NonNull;

import androidx.fragment.app.Fragment;



import com.hhiot.hhvideo.R;



public class settings extends Fragment {

    public View onCreateView(@NonNull LayoutInflater inflater,

                             ViewGroup container, Bundle savedInstanceState) {

        View root = inflater.inflate(R.layout.fr_settings, container, false);



        return root;

    }

}

在构造函数中加载对应的layout(fr_settings)

    1. 新增navigation条目

打开res/navigation/mobile_navigation.xml, 加入一个新条目:

<fragment

    android:id="@+id/nav_Settings"

    android:name="com.hhiot.hhvideo.ui.settings.settings"

    android:label="参数设置"

    tools:layout="@layout/fr_settings" />

注意,此处设置了4个参数:

Id:新的fragment的ID;

Name:对应的Fragment的类名;

Label:将来显示在标题栏上的文字;

Layout:对应的布局文件的名字

    1. 新增按钮

打开文件res/menu/bottom_nav_menu.xml.新增加一个菜单条目(底部显示的按钮):

<item

    android:id="@+id/nav_Settings"

    android:icon="@drawable/ic_notifications_black_24dp"

    android:title="参数设置" />

这里的ID与res/navigation/mobile_navigation.xml中设置的ID一致。

 

    1. 在MainActivity中加入引用

在onCreate中加入新的节点的ID:

@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    BottomNavigationView navView = findViewById(R.id.nav_view);

    // Passing each menu ID as a set of Ids because each

    // menu should be considered as top level destinations.

    AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(

            R.id.nav_VideoList,   R.id.nav_VideoLive,R.id.nav_Desktop, R.id.nav_Settings, R.id.nav_Account)

            .build();

    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);

    NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);

    NavigationUI.setupWithNavController(navView, navController);

}

 

 

  1. ListView设计步骤
    1. 获取数据

通过http获取数据,反序列化成List<Map<String, String>>对象。向主线程发送消息。

void getDatas( ){

    try{

        commHttpUtils.doGetAsyn(dateUrl, new CallBack() {

            @Override

            public void onRequestComplete(String result) {

                List<Map<String, String>> items = new ArrayList<Map<String, String>>();

                items = ( new Gson()).fromJson(result , items.getClass());

                if( msgHandler!=null){

                    try{

                        Message msg = new Message();

                        msg.what = 1000;

                        msg.obj = items;

                        msgHandler.sendMessage(msg);

                    }

                    catch (Exception eer){

                        Log.e(TAG, "onRequestComplete: "+ eer.getMessage() );

                    }

                }

            }

        });

    }

    catch(Exception er){

        Log.e("videoList error.", er.getMessage() );

    }

}

 

相关文章:

  • 2021-10-03
  • 2021-06-22
  • 2021-06-02
  • 2021-12-09
  • 2022-03-07
  • 2021-06-09
猜你喜欢
  • 2021-06-06
  • 2022-01-17
  • 2021-05-17
  • 2021-12-23
  • 2022-02-24
  • 2022-01-01
相关资源
相似解决方案