我的主要活动中有一个用户名和密码字段,当我们启动应用时,键盘会集中在用户名字段上。
但是当您折叠键盘然后尝试单击username
字段时,键盘不会显示,但它适用于password
字段。
这是我的代码:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<RelativeLayout
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#ffffff">
<EditText
android:id="@+id/loginText"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:enabled="true"
android:gravity="center"
android:hint="Login ID"
android:inputType="textEmailAddress"
android:textIsSelectable="true"
android:textStyle="normal" />
<EditText
android:id="@+id/passwordText"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/loginText"
android:layout_alignStart="@+id/loginText"
android:layout_below="@+id/loginText"
android:ems="10"
android:enabled="true"
android:foregroundGravity="center"
android:gravity="center"
android:hint="Password"
android:inputType="textPassword" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/loginText"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:focusableInTouchMode="true"
android:src="@drawable/img" />
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/passwordText"
android:layout_centerHorizontal="true"
android:layout_marginTop="68dp"
android:onClick="checkLogin"
android:text="Login" />
</RelativeLayout>
<ScrollView
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Start the background Firebase activity
serviceIntent = new Intent(this, SendNotificationService.class);
this.stopService(serviceIntent);
//Attempt to show keyboard
//RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.mainLayout);
//relativeLayout.clearFocus();
// Clear userSession
user_Session = null;
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void checkLogin(View view){
EditText loginEditText = (EditText)findViewById(R.id.loginText);
EditText passwordEditText = (EditText)findViewById(R.id.passwordText);
login(loginEditText.getText().toString(), passwordEditText.getText().toString());
}
请帮我调试问题。
答案 0 :(得分:0)
在loginText EditText中删除android:textIsSelectable="true"
行。