好吧!所以这个问题有很多答案。但没有一个对我有用。也许我会在某个地方出错。关闭android默认键盘onClick EditText
我想要做的是,我不想当我点击我的EditText时弹出默认的Android软键盘。
这里是我的xml文件
activity_main.xml中
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="0dp"
android:layout_marginTop="0dp"
android:orientation="horizontal"
android:focusableInTouchMode="true"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="INR"
android:textSize="28dp"
android:layout_marginTop="12dp"
android:layout_marginLeft="55dp"
></TextView>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginLeft="15dp"
android:src="@drawable/indiaflag"
/>
<EditText
android:id="@+id/secondText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:layout_marginLeft="70dp"
android:textSize="28dp"
android:text=""
/>
</LinearLayout>
下面是隐藏在键盘的代码,我使用InputMethodManager没有显示在键盘上的EditText
的点击secondText = (EditText) findViewById(R.id.secondText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(secondText, InputMethodManager.HIDE_NOT_ALWAYS);
我在OnCreate中使用此代码只是在secondText声明后,但这不起作用。我甚至尝试了在setOnClickListener上使用上述代码的替代方法。但仍然没有成功。
谁能告诉我我哪里错了? 在此先感谢
我应该将它添加到onCreate还是setOnClickListener? –
我尝试了你的建议,它像一个魅力。但光标消失。我应该怎么做光标而不是键盘? –
查看已更新的答案 – Jas