2016-10-03 85 views
0

我有自定義鍵盤或數字鍵盤的編輯文本我的問題是當我打開我的應用程序Android鍵盤自動出現我不希望發生這種情況 我的應用程序的想法很簡單,當我點擊編輯文本我的自定義鍵盤出現。 所以我怎麼能刪除的方式,如果我的應用程序手動取消它出現在第一 Android鍵盤就一直沒有出現,但正如我在重新開啓應用程式說再次出現,請大家幫忙如何移除在onCreate時自動出現的鍵盤?

enter image description here

enter image description here

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> 

回答

1

您EDITTEXT變量您剛纔定義清單文件的代碼。

<activity android:name=".activity.HomeScreen" 
      android:windowSoftInputMode="stateAlwaysHidden"/> 

希望這個幫助你..

+0

感謝您的幫助可以幫助我簡單的事情 我想在底部右鍵是輸入或完成按鈕,當我按它不去像新的一行完成按鈕什麼是代碼而不是66,當我按下數字我不想要這個白色高光顯示或標誌 – CJS

+0

你想去完成按鈕上的下一個編輯文本或想在同一個edittext文本 – Sarbjyot

+0

年它是這樣的,但我沒有任何新的編輯文本 – CJS

1

只是這樣做

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 
+0

哪一類我應該把這個? – CJS

1

這將有助於

  InputMethodManager inputMethodManager = (InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE); 
     inputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0); 
+0

我應該把這個放在哪一類? – CJS

+0

在您的onCreate()在KeyboardWidgetTutorialActivity.class –

+0

無論你的第一個事件是發生和鍵盤的彈出 –

0

我用下面這個問題前面的代碼:通過添加以下到相應的活動標記線

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 

使用這種上onCreate()

+0

哪類我應該把這個? – CJS

+0

在''KeyboardWidgetTutorialActivity'類'onCreate'方法下 – harneev

1

您可以隱藏鍵盤清單文件,你的活動:

<activity android:name="packageName.ActivityName" 
    android:windowSoftInputMode="stateHidden" /> 
0

添加以下代碼行中的線性佈局

android:focusable="true"> 
1

添加一個新類Utilities.java包括下面的代碼

public static void hideKeypad(Context context, View edit) { 
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); 
    imm.hideSoftInputFromWindow(edit.getWindowToken(), 0); 
} 

然後在其中調用類,你要隱藏的鍵盤

Utilities.hideKeypad(thisActivity,改爲txtName)下面的代碼;

例子:

txtName的 - >你可以通過這裏

1

創建這個方法並調用它的onCreate():

private void hideSoftKeyBoard() { 
    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); 

    if(imm.isAcceptingText()) { // verify if the soft keyboard is open      
     imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); 
    } 
} 
0

您可以添加

android:focusable="true" 
android:focusableInTouchMode="true" 
android:descendantFocusability="blocksDescendants" 

到的LinearLayout從EditText上移除焦點。