色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:39日期:2022-09-22 13:50:36

本文實例為大家分享了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: android:hint='@string/hint'/> <Button android:text='@string/send' android:layout_width='match_parent' android:layout_height='wrap_content' android: android:onClick='send'/> </LinearLayout></android.support.constraint.ConstraintLayout>

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

響應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); } /** *響應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)建虛擬手機或使用真機測試

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

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

完成。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Android
相關(guān)文章:
主站蜘蛛池模板: 欧美性色欧美a在线播放 | 成人免费毛片观看 | 激情欧美一区二区三区 | 成人高清无遮挡免费视频软件 | 久草在线观看视频 | 欧美日本俄罗斯一级毛片 | 美女被拍拍拍拍拍拍拍拍 | 日本国产最新一区二区三区 | 成人毛片全部免费观看 | 亚洲午夜片子大全精品 | 久草一级片 | 亚洲综合黄色 | 欧美牲 | 日韩成人毛片高清视频免费看 | 国产伦久视频免费观看 视频 | 免费a级毛片无码 | 国内精品小视频福利网址 | 911精品国产亚洲日本美国韩国 | 美女操男人| 91亚洲国产成人久久精品网址 | 国产爽的冒白浆的视频高清 | 成年人福利视频 | 欧美一级毛片高清毛片 | 欧美日韩在线视频 | 看中国一级毛片 | 国产精品久久久久久久午夜片 | 免费一区二区三区四区五区 | 国产精品美女视视频专区 | 国产成人精品高清免费 | 手机看福利片 | 久久机热综合久久国产 | 国产三级a三级三级午夜 | 日韩一级黄色 | 免费国产成人午夜在线观看 | 国产高清自拍一区 | 欧美中文一区 | 欧美h版成版在线观看 | 日本加勒比在线 | 国产亚洲精品久久久久久久网站 | 一级做a爰片久久毛片 | 国产综合成人亚洲区 |