我正在使用输入框AlertDialog
.在EditText
该对话框中本身自动对焦,当我打电话AlertDialog.show()
,但软键盘未自动显示.
如何在显示对话框时自动显示软键盘?(并且没有物理/硬件键盘).与按下"搜索"按钮调用全局搜索的方式类似,将自动显示软键盘.
我有一个EditText-Field并为它设置一个OnFocusChangeListener.当它失去焦点时,会调用一个方法,该方法使用数据库中的一个方法检查EditText的值.如果方法的返回值为true,则显示toast,焦点应再次返回EditText.焦点应始终返回EditText并且键盘应该显示,直到方法的返回值为false.
编辑:我想,我还没有完全清楚我的真正问题:屏幕上没有其他项目应该能够编辑,直到EditText的值被编辑为一个值,这使得方法"checkLiganame(liganame) "回归虚假.只有EditText-Field应该是可编辑的.
这是我的代码(这对我不起作用):
final EditText Liganame = (EditText) findViewById(R.id.liganame);
Liganame.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
String liganame = Liganame.getText().toString();
if (checkLiganame(liganame)) {
Toast toast = Toast.makeText(CreateTableActivity.this,
"Dieser Liganame ist bereits vergeben",
Toast.LENGTH_SHORT);
toast.show();
Liganame.requestFocus();
}
}
Run Code Online (Sandbox Code Playgroud)
和方法:
public boolean checkLiganame(String liganame) {
boolean found = false;
DatabaseHelper databaseHelper = new DatabaseHelper(this);
SQLiteDatabase db = databaseHelper.getReadableDatabase();
Cursor cursor = db.query("liga", new String[] { "liganame" },
"liganame = '" + liganame + "'", …
Run Code Online (Sandbox Code Playgroud) 我有一个布局,其中包含一些像这样的视图:
<LinearLayout>
<TextView...>
<TextView...>
<ImageView ...>
<EditText...>
<Button...>
</linearLayout>
Run Code Online (Sandbox Code Playgroud)
如何以EditText
编程方式设置焦点(显示键盘)?
我已经尝试了这个,只有当我Activity
正常启动时它才有效,但是当我在a中启动它时TabHost
,它不起作用.
txtSearch.setFocusableInTouchMode(true);
txtSearch.setFocusable(true);
txtSearch.requestFocus();
Run Code Online (Sandbox Code Playgroud) 任何人都可以解释"android.R.id.content"的含义?
它是如何使用的?
http://developer.android.com没有任何解释.
public static final int contents
自:API Level 1常数值:16908290(0x01020002)
我有一个在ImageView上面有一个Edittext字段的视图.当键盘出现时,我希望窗口调整大小,以便键盘不再隐藏EditText.在我宣布的AndroidManifest文件中android:windowSoftInputMode="adjustResize"
,屏幕调整大小,但问题是我希望ImageView不能重新调整大小.如何使ImageView不受影响?
我可以仅使用ImageView来扩充其他布局,还是调整大小仍会影响它?
请解释一下软键盘的问题.例如,我在我的活动或对话片段或片段活动上有一个EditText,无论如何.这里是:
<EditText
android:id="@+id/edPswrd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" >
<requestFocus />
</EditText>
Run Code Online (Sandbox Code Playgroud)
当它第一次显示我没有看到软键盘并且必须按editText才能获得焦点并且键盘出现.另一个活动是不同的,当它出现在屏幕上时,键盘在没有任何帮助的情况下加载.我以为
<requestFocus />
意味着EditText将被聚焦并且键盘将出现,但我错了.
如何管理哪些组件将获得焦点,键盘将自动显示.
我创建了customview.每当用户双击视图时,它应显示键盘,用户可以绘制新文本.
Holder是一个扩展视图的自定义视图.但它正在显示键盘.如何获取文字?
public Holder(Context context, AttributeSet attrs) {
super(context, attrs);
Log.e(TAG,"EXE");
imm = (InputMethodManager)
context. getSystemService(Context.INPUT_METHOD_SERVICE);
public boolean onDoubleTap(MotionEvent e) {
View view = Holder.this.getRootView();
imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
// imm.showSoftInput(Holder.this, InputMethodManager.SHOW_FORCED); not working
Run Code Online (Sandbox Code Playgroud) 我有一个EditText,我将焦点传递给编程.但是当我这样做时,我希望键盘也能显示出来(然后当EditText失去焦点时向下移动).现在,用户必须单击EditText才能显示键盘 - 甚至认为EditText已经具有焦点.
当我的EditText获得焦点时,我想显示键盘.我尝试了很多方法,但没有任何帮助.我试过了:1.
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
Run Code Online (Sandbox Code Playgroud)
不同的旗帜.
2.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
<requestFocus />
4.
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
editText.post(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}
});
}
});
editText.requestFocus();
Run Code Online (Sandbox Code Playgroud)
4方法是fork但它解决不好.这样写在这里当EditText获得焦点时自动显示软键盘
之前,我使用方法2并且它有效.但现在不再.我创建了一个空白项目,它不起作用,没有一个方法
更新:
<style name="Theme.TransparencyDemo" parent="android:Theme.Light.NoTitleBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
Run Code Online (Sandbox Code Playgroud) 好吧,我已经尝试了我在stackoverflow和其他地方找到的所有解决方案,但最终结果没有改变一点:触发onKey事件的唯一键或dispatchKeyEvent是虚拟键盘上的回车键,并且只有按两次.我无法拦截任何其他键(事件顶部有一个断点,eclipse永远不会停在它上面,除非是上述输入).Beheaviour在仿真器和真实设备上都是相同的.有任何想法吗?提前谢谢我的代码atm看起来像这样:
public class ChatWindow {
@Override
public void onCreate(Bundle savedInstanceState) {
//...
setSendText();
//...
}
private void setUserInput() {
Intent i = getIntent();
mChatInput = (EditText) findViewById(R.id.UsrInput);
if (i.hasExtra(INTENT_EXTRA_MESSAGE)) {
mChatInput.setText(i.getExtras().getString(INTENT_EXTRA_MESSAGE));
}
mChatInput.setFocusable(true);
mChatInput.requestFocus();
mChatInput.setFocusableInTouchMode(true);
mChatInput.addTextChangedListener(new TextWatcher() {
public void afterTextChanged (Editable s){
Log.d(TAG, "afterTextChanged");
if (mChatInput.getText().length() >= 1) {
mChatInput.addTextChangedListener(this);
//mChatInput.setOnKeyListener(this);
//mChatInput.dispatchKeyEvent(this);
mSendButton.setEnabled(true);
}
else
mSendButton.setEnabled(false);
}
public void beforeTextChanged (CharSequence s, int start, int
count, int after)
{
Log.d(TAG, "beforeTextChanged");
}
public void onTextChanged (CharSequence s, int start, …
Run Code Online (Sandbox Code Playgroud)