[AndroidUI Design] Adding Fragment in Bottom Navigation Activity and modifying the lower navigation icon

I. Introduction

  • Description: In actual development, Fragment is a frequently used layout. Android studio has a one-click way to generate Fragment layout, Bottom Navigation Activity, so how do we add Fragments and modify the lower navigation icon on this basis?
  • Difficulty: Beginner
  • Effect
    Insert image description here

2. Design

1. Add Fragment

(1) Confirm requirements

Suppose you need to add a personal information interface fragment on the original basis, named: info

Insert image description here

(2) Create
     <1> Method 1: Use tools to quickly generate

Create a Fragment (with ViewModel) as shown in the figure. Of course, if there is no data that needs to be dynamically modified and a simple interface, you can choose Modal Bottom Sheet.

Insert image description here

     <2> Method 2: View (layer) tool

Select Gallery

Insert image description here

Enter Gallery and choose according to your needs

Insert image description here

     <3> Method 3: Manual creation

First create an Activity

Insert image description here
Insert image description here

Make the following modifications

Insert image description here

(3)Add
     <1> Add fragment attributes (naming, icon)

In order to take care of beginners, the modification of the icon is in the next chapter

Insert image description here

	<string name="title_info">Info</string>

Insert image description here

     <2> Add sub-items to the menu (bottom_nav_menu.xml) file

Insert image description here

	<item
        android:id="@+id/navigation_info"
        android:icon="@drawable/ic_notifications_black_24dp"
        android:title="@string/title_info"/>

Insert image description here

     <3> Add fragment interface

Insert image description here

    <fragment
        android:id="@+id/navigation_info"
        android:name="com.hngy.xpq.fragmentdemo.ui.info.InfoFragment"
        android:label="@string/title_info"
        tools:layout="@layout/fragment_info" />

Insert image description here

(4) Effect
  • Before adding (three fragment layout)

Insert image description here

  • After adding (four fragment layout)

Insert image description here

2. Modify the underlying icon

(1) Icon resources
     <1> Method 1: Design with PS

Insert image description here

     <2> Method 2: Alibaba vector icon library

Alibaba vector icon library URL: https://www.iconfont.cn/collections/index?spm=a313x.7781069.1998910419.6&type=2

Insert image description here

(2) Download resources
     <1> Add to database

Insert image description here

     <2> Open shopping cart

Insert image description here

     <3> Download

Insert image description here

     <4> Select svg

Insert image description here

(3) Use
     <1> Open svg file

Insert image description here

     <2> F12 find element

Insert image description here

     <3> Create resource files in Android studio

Insert image description here

     <4> Modify file content

According to the element content obtained by F12, it is known that (width, height) = 200px, (viewportWidth, viewportHeight) = 1024, and the path is modified according to the element.

Insert image description here

     <5> Modify layout file

Insert image description here

Insert image description here

     <6> Effect
  • Before modification

Insert image description here

  • after modification

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_48916759/article/details/131395727