TextView和EditText

TextView

TextView创建链接

android:textIsSelectable="true"(文字可以被选中)




    

TextView和EditText_第1张图片

EditText




    

    

package com.example.android03;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private TextView textview_email;
    private EditText editText_name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //绑定布局文件
        setContentView(R.layout.activity_main);

        //根据ID查找组件
        textview_email = (TextView) findViewById(R.id.textview_email);

        textview_email.setText("[email protected]");

        editText_name = (EditText)findViewById(R.id.editText_name);
        editText_name.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {//输入文字前
                System.out.println("beforeTextChanged--"+s);
            }

            @Override//输入文字时
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                System.out.println("onTextChanged--"+s);
            }

            @Override//输入文字后
            public void afterTextChanged(Editable s) {
                System.out.println("afterTextChanged--"+s);
            }
        });
        //监听回车键
        editText_name.setOnEditorActionListener(new TextView.OnEditorActionListener(){
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event){
                Toast.makeText(MainActivity.this,v.getText().toString(),Toast.LENGTH_LONG).show();
                return true;
            }
        });
    }


}

TextView和EditText_第2张图片

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