第一个DEMO app

从一个android小白开始学习:

1、安装android studio 3.0

2、安装JAVA SDK

3、编写一个APP,点击发送能够将写入字符输出到屏幕上。

总共4个文件:

MainActivity.xml

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

    <EditText android:id="@+id/edit_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message"
        />

    <Button
        android:id="@+id/sendmessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_send"


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/edit_message2" />
    <TextView
        android:id="@+id/myTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

LinearLayout>

string.xml


<resources>
    <string name="app_name">demostring>
    <string name="sction_settings">Settingsstring>
    <string name="edit_message">输入一条信息string>
    <string name="button_send">发送string>
    <string name="edit_message2">您输入的信息是string>
resources>
AndroidManifest.xml
xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.admin.demo">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

manifest>

MainActivity.java

package com.example.admin.demo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
    protected Button btn;
     @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn =(Button)findViewById(R.id.sendmessage);
        //findViewById(R.id.sendMessage).setOnClickListener(this);
        btn.setOnClickListener(new View.OnClickListener() {       //设置按钮单击事件
            @Override
            public void onClick(View v) {
                EditText et = findViewById(R.id.edit_message);//获取edittext组件
                TextView tv = findViewById(R.id.myTextView);//获取textview组件
                String cn = et.getText().toString();//获取edittext中填写的内容
                tv.setText(cn);//在textview中显示
            }
        });

    }
}

你可能感兴趣的:(学习)