2017-10-02 1 views
1

キーボードが存在するときにユーザーがナビゲーションドロワーメニューを開くのを防止します。私は、TextFieldに「フォーカス」と「ぼかし」のリスナーを追加してみました:キーボードが存在するときに引き出しメニューが表示されないようにしますか? (Android Appcelerator)

$.searchField.addEventListener('focus', function(e) { 
    Ti.API.info('locked drawer'); 
    $.drawerLayout.drawerLockMode = Titanium.UI.Android.DrawerLayout.LOCK_MODE_LOCKED_CLOSED; 
}); 

$.searchField.addEventListener('blur', function(e) { 
    Ti.API.info('unlocked drawer'); 
    $.drawerLayout.drawerLockMode = Titanium.UI.Android.DrawerLayout.LOCK_MODE_UNLOCKED; 
}); 

しかし、あなたは何も起こりません見ることができますように。

答えて

-1

このコードのコードをあなたのアクティビティの追加

@Override 
public boolean dispatchTouchEvent(MotionEvent ev) { 
    View v = getCurrentFocus(); 
    if (v != null && 
      (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_MOVE) && 
      v instanceof EditText && 
      !v.getClass().getName().startsWith("android.webkit.")) { 
     int scrcoords[] = new int[2]; 
     v.getLocationOnScreen(scrcoords); 
     float x = ev.getRawX() + v.getLeft() - scrcoords[0]; 
     float y = ev.getRawY() + v.getTop() - scrcoords[1]; 
     if (x < v.getLeft() || x > v.getRight() || y < v.getTop() || y > v.getBottom()) 
      hideKeyboard(this); 
    } 
    return super.dispatchTouchEvent(ev); 
} 

public void hideKeyboard(Activity activity) { 
    if (activity != null && activity.getWindow() != null && activity.getWindow().getDecorView() != null) { 
     InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); 
     imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0); 
    } 
} 
+0

私はAppcelerator Titaniumを使用しています。ネイティブ開発ではありません。 – guillefix

+0

申し訳ありません@guillefix –

+0

@RameshYogu、答えを入れる前に質問を正しく検討してください。この質問はチタンのためのものであることをはっきりと示していました。 –

1

私はこれを使用してNL Fokke Drawer Widgetとしました。

XML::

<Alloy> 
    <Widget id="drawer" src="nl.fokkezb.drawer"> 
    <View module="xp.ui" role="leftWindow"> 

    </View> 

    <NavigationWindow module="xp.ui" platform="ios" role="centerWindow"> 
     <Window> 
      <Require src="homeView"></Require> 
     </Window> 
    </NavigationWindow> 

    <Window module="xp.ui" platform="android" role="centerWindow"> 
     <Require src="homeView"></Require> 
    </Window> 
</Widget> 

JS:

このウィジェットを使用する

、私はこのように私のウィンドウを作成しました

このウィジェットを使用していない場合は、このウィジェットのコード&とコードを一致させることができます。ロックモードの設定方法をご覧ください。

+0

私はドロワーをロック/ロック解除する方法を知っていますが、私が望むのは、キーボードが存在するときにユーザーがTextFieldをタイプしているときにドロワーをロックし、キーボードが存在しないときにドロアーをロックすることです。 – guillefix

+0

あなたのフォーカス&ブラーイベントは起動していませんか?コードの残りの部分が私にはうまく見えたからです。 –

+0

はい、私のイベントは起動しません。 – guillefix

関連する問題