深圳全飞鸿

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 581|回复: 2
打印 上一主题 下一主题

Bottom Navigation Activity

[复制链接]

800

主题

1379

帖子

7725

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7725
跳转到指定楼层
楼主
发表于 2019-5-21 23:04:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.     package="com.example.administrator.myapplication2">

  4.     <application
  5.         android:allowBackup="true"
  6.         android:icon="@mipmap/ic_launcher"
  7.         android:label="@string/app_name"
  8.         android:roundIcon="@mipmap/ic_launcher_round"
  9.         android:supportsRtl="true"
  10.         android:theme="@style/AppTheme">
  11.         <activity
  12.             android:name=".MainActivity"
  13.             android:label="@string/app_name">
  14.             <intent-filter>
  15.                 <action android:name="android.intent.action.MAIN" />

  16.                 <category android:name="android.intent.category.LAUNCHER" />
  17.             </intent-filter>
  18.         </activity>
  19.     </application>

  20. </manifest>
复制代码
回复

使用道具 举报

800

主题

1379

帖子

7725

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7725
沙发
 楼主| 发表于 2019-5-21 23:04:21 | 只看该作者
  1. package com.example.administrator.myapplication2;

  2. import android.os.Bundle;
  3. import android.support.annotation.NonNull;
  4. import android.support.design.widget.BottomNavigationView;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.view.MenuItem;
  7. import android.widget.TextView;

  8. public class MainActivity extends AppCompatActivity {

  9.     private TextView mTextMessage;

  10.     private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
  11.             = new BottomNavigationView.OnNavigationItemSelectedListener() {

  12.         @Override
  13.         public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  14.             switch (item.getItemId()) {
  15.                 case R.id.navigation_home:
  16.                     mTextMessage.setText(R.string.title_home);
  17.                     return true;
  18.                 case R.id.navigation_dashboard:
  19.                     mTextMessage.setText(R.string.title_dashboard);
  20.                     return true;
  21.                 case R.id.navigation_notifications:
  22.                     mTextMessage.setText(R.string.title_notifications);
  23.                     return true;
  24.             }
  25.             return false;
  26.         }
  27.     };

  28.     @Override
  29.     protected void onCreate(Bundle savedInstanceState) {
  30.         super.onCreate(savedInstanceState);
  31.         setContentView(R.layout.activity_main);

  32.         mTextMessage = (TextView) findViewById(R.id.message);
  33.         BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
  34.         navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
  35.     }

  36. }
复制代码
回复 支持 反对

使用道具 举报

800

主题

1379

帖子

7725

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7725
板凳
 楼主| 发表于 2019-5-21 23:04:33 | 只看该作者
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:id="@+id/container"
  6.     android:layout_width="match_parent"
  7.     android:layout_height="match_parent"
  8.     tools:context="com.example.administrator.myapplication2.MainActivity">

  9.     <TextView
  10.         android:id="@+id/message"
  11.         android:layout_width="wrap_content"
  12.         android:layout_height="wrap_content"
  13.         android:layout_marginLeft="@dimen/activity_horizontal_margin"
  14.         android:layout_marginStart="@dimen/activity_horizontal_margin"
  15.         android:layout_marginTop="@dimen/activity_vertical_margin"
  16.         android:text="@string/title_home"
  17.         app:layout_constraintLeft_toLeftOf="parent"
  18.         app:layout_constraintTop_toTopOf="parent" />

  19.     <android.support.design.widget.BottomNavigationView
  20.         android:id="@+id/navigation"
  21.         android:layout_width="0dp"
  22.         android:layout_height="wrap_content"
  23.         android:layout_marginEnd="0dp"
  24.         android:layout_marginStart="0dp"
  25.         android:background="?android:attr/windowBackground"
  26.         app:layout_constraintBottom_toBottomOf="parent"
  27.         app:layout_constraintLeft_toLeftOf="parent"
  28.         app:layout_constraintRight_toRightOf="parent"
  29.         app:menu="@menu/navigation" />

  30. </android.support.constraint.ConstraintLayout>
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|nagomes  

GMT+8, 2025-6-29 01:11 , Processed in 0.053830 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表