欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實現(xiàn)界面跳轉(zhuǎn)功能

 更新時間:2020年09月23日 14:09:34   作者:Red&&Black  
這篇文章主要為大家詳細介紹了Android實現(xiàn)界面跳轉(zhuǎn)功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android實現(xiàn)界面跳轉(zhuǎn)的具體代碼,供大家參考,具體內(nèi)容如下

布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
  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"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity">

 <!-- 線性布局 、垂直排列 -->
 <LinearLayout
   android:orientation="vertical"
   android:layout_width="match_parent"
   android:layout_height="match_parent">
  <!-- 編輯框 
 @string/hint 表示 res/values/strings.xml下名為hint的標簽
    strings.xml用于字符串資源及其格式化
  -->
  <EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:text="Name"
    android:ems="10"
    android:id="@+id/input" android:hint="@string/hint"/>
  <Button
    android:text="@string/send"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" android:id="@+id/button2" android:onClick="send"/>
 </LinearLayout>


</android.support.constraint.ConstraintLayout>

或者點擊text左邊的design進行布局

響應(yīng)onclick

package com.android02;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

 //定義常量,作為消息的key
 public final static String MESSAGE_KEY="com.android2";

 @Override
 protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);
  /**
   * 指定布局(res下的activity_main.xml編譯成r.java)
   */
  setContentView(R.layout.activity_main);
 }

 /**
  *響應(yīng)onclick事件
  */
 public void send(View button){

  //以id獲取EditText
  EditText editText = findViewById(R.id.input);

  //獲取編輯框文字
  String message = editText.getText().toString();

 //activity、service和broadcast receiver通過Intent進行交互
  Intent intent = new Intent(this,ReceiveActivity.class);

  //在intent中附加信息
  intent.putExtra(MESSAGE_KEY,message);
  startActivity(intent);
 }

}

創(chuàng)建ReceiveActivity

右擊java>>new>>Activity>>Empty Activity
然后進入創(chuàng)建頁面指定Activity的名字…
然后它在AndroidManifest.xml中自動注冊

package com.android02;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class ReceiveActivity extends AppCompatActivity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_receive);

  //獲取intent引用
  Intent intent = getIntent();

  //以MESSAGE_KEY獲取獲取編輯框文字
  String message = intent.getStringExtra(MainActivity.MESSAGE_KEY);

  //以id獲取TextView
  TextView textView = findViewById(R.id.output);

  //顯示message
  textView.setText(message);

 }
}

測試

通過AVD manager 創(chuàng)建虛擬手機或使用真機測試

完成。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android端代碼量非常小的分頁加載庫

    Android端代碼量非常小的分頁加載庫

    這篇文章主要給大家介紹了關(guān)于Android端代碼量非常小的分頁加載庫的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-03-03
  • android九宮格可分頁加載控件使用詳解

    android九宮格可分頁加載控件使用詳解

    這篇文章主要介紹了android九宮格可分頁加載控件的使用方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • Android加載Gif動畫實現(xiàn)代碼

    Android加載Gif動畫實現(xiàn)代碼

    這篇文章主要為大家詳細介紹了Android加載Gif動畫實現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Android仿抖音主頁效果實現(xiàn)代碼

    Android仿抖音主頁效果實現(xiàn)代碼

    這篇文章主要介紹了Android仿抖音主頁效果實現(xiàn),本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-12-12
  • Android實現(xiàn)檢查并下載APK更新、安裝APK及獲取網(wǎng)絡(luò)信息的方法

    Android實現(xiàn)檢查并下載APK更新、安裝APK及獲取網(wǎng)絡(luò)信息的方法

    這篇文章主要介紹了Android實現(xiàn)檢查并下載APK更新、安裝APK及獲取網(wǎng)絡(luò)信息的方法,很實用的功能,需要的朋友可以參考下
    2014-07-07
  • Android編程實現(xiàn)滑動按鈕功能詳解

    Android編程實現(xiàn)滑動按鈕功能詳解

    這篇文章主要介紹了Android編程實現(xiàn)滑動按鈕功能,結(jié)合實例形式較為詳細的分析了Android實現(xiàn)滑動按鈕的功能、布局及相關(guān)注意事項,需要的朋友可以參考下
    2017-02-02
  • Android Shape控件美化實現(xiàn)代碼

    Android Shape控件美化實現(xiàn)代碼

    本文主要介紹Android Shape 控件的美化, 大家在開發(fā)Android程序的時候?qū)ο到y(tǒng)自帶的控件進行修改,這里給大家一個實例,供大家參考
    2016-07-07
  • Android中利用zxing實現(xiàn)自己的二維碼掃描識別詳解

    Android中利用zxing實現(xiàn)自己的二維碼掃描識別詳解

    這篇文章主要給大家介紹了關(guān)于Android中利用zxing實現(xiàn)自己的二維碼掃描識別的相關(guān)資料,文中通過圖文介紹的非常詳細,對大家學習或者使用zxing具有一定的參考學習價值,需要的朋友們下面來一起看看吧。
    2017-09-09
  • 適用于Android開發(fā)的簡單聊天軟件

    適用于Android開發(fā)的簡單聊天軟件

    為大家介紹一個手機App開發(fā)項目,簡單的聊天軟件,適用于Android開發(fā),感興趣的小伙伴們可以參考一下
    2016-07-07
  • Android Studio+Servlet+MySql實現(xiàn)登錄注冊

    Android Studio+Servlet+MySql實現(xiàn)登錄注冊

    對于大多數(shù)的APP都有登錄注冊這個功能,本文就來介紹一下Android Studio+Servlet+MySql實現(xiàn)登錄注冊,需要的朋友們下面隨著小編來一起學習學習吧
    2021-05-05

最新評論