简短的回答:
<EditText
android:id="@+id/et_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:focusableInTouchMode="false"
android:scrollHorizontally="true" />
例如,如何使用 PopUpWindow 代替默认键盘:
//Your Main Layout
RelativeLayout mainLayout = (RelativeLayout)findViewById(R.id.activity_rl);
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
//Set layout instead keyboard (Linear layout with buttons)
View popupView = layoutInflater.inflate(R.layout.keyboard, null);
PopupWindow ppwin = new PopupWindow(popupView, LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
//Some Button on that Linear layout
Button bt = (Button)popupView.findViewById(R.id.button1);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
edit_text.setText(edit_text.getText().toString()+"Your text");
}
});
//Your EditText in Main layout
EditText edit_text = (EditText)findViewById(R.id.et_1);
edit_text .setOnTouchListener(new OnTouchListener() {
@Override public boolean onTouch(View v, MotionEvent event) {
//show PopUpWindow with buttons instead default keyboard
//or your custom keyboard
ppwin.showAtLocation(mainLayout, Gravity.BOTTOM, 0, 0);
return false;
}
});