国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Android實現界面跳轉功能

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

本文實例為大家分享了Android實現界面跳轉的具體代碼,供大家參考,具體內容如下

布局

<?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); }}

創建ReceiveActivity

右擊java>>new>>Activity>>Empty Activity然后進入創建頁面指定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 創建虛擬手機或使用真機測試

Android實現界面跳轉功能

Android實現界面跳轉功能

完成。

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

標簽: Android
相關文章:
主站蜘蛛池模板: 亚洲社区在线观看 | 国产精品久久久久久久久久影院 | 国产激情自拍 | 九九热精品在线 | 欧美 另类 精品一区视频 | 国产精品久久成人影院 | 成人男女啪啪免费观看网站 | 亚洲综合一区二区不卡 | 欧美大片一级毛片 | 毛片免费观看网址 | 女人一级一级毛片 | 亚洲国产精品91 | 国产香港特级一级毛片 | 一级做性色a爰片久久毛片 一级做性色a爰片久久毛片免费 | 欧美日韩一级大片 | 国产男女在线观看 | 香蕉久久夜色精品国产 | 欧美一级毛片一级毛片 | 成人在线播放视频 | 新版天堂资源中文在线 | 国产日韩精品视频一区二区三区 | 久久国产美女免费观看精品 | 欧美国产合集在线视频 | 精品国产区一区二区三区在线观看 | 91久久精品国产一区二区 | 91国语精品自产拍在线观看一 | 久久不见久久见免费影院www日本 | 日韩欧美色综合 | 欧美成人免费夜夜黄啪啪 | 99re7在线精品免费视频 | 久久不见久久见免费影院 | 在线高清一级欧美精品 | 亚洲自偷自偷图片在线高清 | 日本欧美一级二级三级不卡 | 在线观看毛片网站 | 99久久这里只精品国产免费 | 亚洲日产2021三区 | 中文国产成人精品久久一区 | 奇米影视7777久久精品 | 亚洲国产一级毛片 | 亚洲乱淫|