Android基本控件 - 文本框

<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="cn.appio.testedit.MainActivity">

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="psone"
        android:imeActionId="1"
        android:imeActionLabel="下一个"
        android:imeOptions="actionNext"
        android:inputType="text"
        android:text="Name1"
        tools:layout_editor_absoluteX="69dp"
        tools:layout_editor_absoluteY="1dp" />

android.support.constraint.ConstraintLayout>

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;

import android.view.KeyEvent;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

public class MainActivity extends AppCompatActivity {

    Button btn = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        EditText txt1 = (EditText) findViewById(R.id.editText1);
        txt1.setOnEditorActionListener( new OnEditorListener());
    }

    private class OnEditorListener implements OnEditorActionListener {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ( actionId == 1 ) {
                Toast.makeText(MainActivity.this, "你点了软键盘按钮",Toast.LENGTH_SHORT).show();
            }

            return false;
        }
    }
}

//待续

你可能感兴趣的:(Android)