사용자 정의 키보드 또는 숫자 패드로 텍스트 편집이 있습니다. 내 문제는 내 앱을 열 때 안드로이드 키보드가 자동으로 나타납니다. 텍스트 편집을 클릭하면 앱 아이디어가 간단합니다. 사용자 정의 키보드가 나타납니다. 그래서 앱에서 수동으로 취소하면 처음에 나타나는 안드로이드 키보드를 제거하는 방법은 나타나지 않지만 다시 열 때 앱이 다시 나타납니다.
public class BasicOnKeyboardActionListener implements OnKeyboardActionListener {
private Activity mTargetActivity;
/***
*
* @param targetActivity
* Activity a cui deve essere girato l'evento
* "pressione di un tasto sulla tastiera"
*/
public BasicOnKeyboardActionListener(Activity targetActivity) {
mTargetActivity = targetActivity;
}
@Override
public void swipeUp() {
// TODO Auto-generated method stub
}
@Override
public void swipeRight() {
// TODO Auto-generated method stub
}
@Override
public void swipeLeft() {
// TODO Auto-generated method stub
}
@Override
public void swipeDown() {
// TODO Auto-generated method stub
}
@Override
public void onText(CharSequence text) {
// TODO Auto-generated method stub
}
@Override
public void onRelease(int primaryCode) {
// TODO Auto-generated method stub
}
@Override
public void onPress(int primaryCode) {
// TODO Auto-generated method stub
}
@Override
public void onKey(int primaryCode, int[] keyCodes) {
long eventTime = System.currentTimeMillis();
KeyEvent event = new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN, primaryCode, 0, 0, 0, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);
mTargetActivity.dispatchKeyEvent(event);
}
CustomKeyboardView.class
public class CustomKeyboardView extends KeyboardView {
public CustomKeyboardView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void showWithAnimation(Animation animation) {
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
setVisibility(View.VISIBLE);
}
});
setAnimation(animation);
}
KeyboardWidgetTutorialActivity.class
public class KeyboardWidgetTutorialActivity extends Activity {
private CustomKeyboardView mKeyboardView;
private View mTargetView;
private Keyboard mKeyboard;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mKeyboard = new Keyboard(this, R.xml.keyboard);
mTargetView = (EditText) findViewById(R.id.target);
mTargetView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// Dobbiamo intercettare l'evento onTouch in modo da aprire la
// nostra tastiera e prevenire che venga aperta quella di
// Android
showKeyboardWithAnimation();
return true;
}
});
mKeyboardView = (CustomKeyboardView) findViewById(R.id.keyboard_view);
mKeyboardView.setKeyboard(mKeyboard);
mKeyboardView
.setOnKeyboardActionListener(new BasicOnKeyboardActionListener(
this));
}
/***
* Mostra la tastiera a schermo con una animazione di slide dal basso
*/
private void showKeyboardWithAnimation() {
if (mKeyboardView.getVisibility() == View.GONE) {
Animation animation = AnimationUtils
.loadAnimation(KeyboardWidgetTutorialActivity.this,
R.anim.slide_in_bottom);
mKeyboardView.showWithAnimation(animation);
}
}
이것은 주요 XML입니다
<RelativeLayout android:id="@+id/LinearLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/container" android:layout_alignParentTop="true"
android:layout_height="fill_parent" android:layout_above="@+id/keyboard_view">
<EditText android:layout_width="fill_parent" android:id="@+id/target"
android:layout_height="wrap_content" />
</LinearLayout>
<it.anddev.tutorial.CustomKeyboardView
android:id="@+id/keyboard_view" android:visibility="gone"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"></it.anddev.tutorial.CustomKeyboardView>
매니페스트 파일에서 해당 코드를 정의하기 만하면됩니다.
<activity android:name=".activity.HomeScreen"
android:windowSoftInputMode="stateAlwaysHidden"/>
도움이 되었기를 바랍니다 ..
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다