亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

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

本文實(shí)例為大家分享了Android實(shí)現(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的標(biāo)簽 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>

或者點(diǎn)擊text左邊的design進(jìn)行布局

響應(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進(jìn)行交互 Intent intent = new Intent(this,ReceiveActivity.class); //在intent中附加信息 intent.putExtra(MESSAGE_KEY,message); startActivity(intent); }}

創(chuàng)建ReceiveActivity

右擊java>>new>>Activity>>Empty Activity然后進(jìn)入創(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)建虛擬手機(jī)或使用真機(jī)測試

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

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

完成。

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

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: jizz国产精品| 91麻豆网址| 99re这里有免费视频精品 | www.黄色| 欧美日韩不卡视频一区二区三区 | 精品一本久久中文字幕 | 亚洲国产第一区二区三区 | 日韩精品高清自在线 | 特级全黄一级毛片免费 | 特黄特色一级特色大片中文 | 污视频在线网站 | 亚洲高清国产一线久久 | 国产一级做性视频 | 中文字幕综合久久久久 | 免费a大片| 超级极品白嫩美女在线 | 国产成人精品视频一区二区不卡 | 国产欧美日韩视频怡春院 | 色琪琪原网站亚洲香蕉 | 九九99精品 | aabb片免费看 | 91久久国产情侣真实对白 | 亚洲一区二区观看 | 国产爱久久久精品 | 亚洲欧美日韩国产综合 | 午夜精品一区二区三区在线视 | 中文字幕一区二区视频 | 欧美精品啪啪 | 国产伦精品一区二区三区网站 | 成人免费看黄页网址大全 | 香蕉手机网 | 日本一级片在线观看 | 一级毛片一级毛片a毛片欧美 | 国产开嫩苞实拍在线播放视频 | 久久精品免视看国产明星 | 性色视频免费 | 三级黄在线 | 国产精品免费一区二区三区四区 | 九九热最新视频 | 免费毛片a| 99久久免费看国产精品 |