触摸编辑文本时键盘不会显示

时间:2016-09-02 04:25:26

标签: android android-studio android-edittext android-softkeyboard

我在genymotion上测试我的应用程序。我希望键盘在触摸编辑文本时显示,请帮助我。 this is the screen shot of my app

这是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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#5a5ab5"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:clickable="false">

<com.github.florent37.materialtextfield.MaterialTextField
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/view"
    app:mtf_image="@drawable/phon"
    android:id="@+id/view3">

<EditText
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:id="@+id/phoneNo"
    android:paddingLeft="5dp"
    android:textSize="18sp"
    android:inputType="phone"
    android:background="@drawable/phone"
    android:hint="Phone Number"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

5 个答案:

答案 0 :(得分:2)

尝试在您的清单文件中添加以下代码(在您的活动代码中):

Rather than storing a value ,Computed property provides a getter and ,optionally a setter which indirectly retrieve and set other properties and values respectively .

struct Point 
 {
var x = 0.0 ,y = 0.0
}
struct Shape 
{
var origin = Point ( )
var centre : Point {
get
{
return Point (x:origin.x/2 y:origin.y/2)
}
set(newCentre )
{
origin.x = newCentre.x/2
origin.y = newCentre.y/2
}
}
}
}

The Shape structure defines a custom getter and setter method for computed variable called Centre .The Centre 
property then access through dot syntax ,which causes getter for centre to be called retrieve the current property value .Rather than returning a existing value ,the getter actually calculates and returns a new point that represent centre of the shape .
     If a Computed property setter does not define a name for the  new value to be set a default name of "newValue" is used 

   Below is an alternative version of Rect structure ,which takes advantage of this shorthand notation.

struct Point 
 {
var x = 0.0 ,y = 0.0
}
struct Shape 
{
var origin = Point ( )
var centre : Point {
get
{
return Point (x:origin.x/2 y:origin.y/2)
}
set(newCentre )
{
origin.x = newValue.x/2
origin.y = newValue.y/2
}
}
}
}

Important - A computed property with a getter but no setter is known as read only Computed Property .It always returns a value and can be accessed through dot syntax .However the value can't be altered .

OR

android:windowSoftInputMode="stateAlwaysVisible"

希望这有帮助。

答案 1 :(得分:1)

正如您在代码中所描述的,您在代码中使用了Material Library。请阅读此库文档。 显示键盘代码已在说明中描述。

app:mtf_openKeyboardOnFocus="true"

在此处添加您的素材观看次数Material Library Description

答案 2 :(得分:0)

使用这种方式,当EditText为焦点时,它将显示键盘

EditText phoneNo= (EditText) findViewById(R.id.phoneNo);
phoneNo.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

答案 3 :(得分:0)

在您的布局xml文件中将此行添加到To EditText

android:focusableInTouchMode="true"

这对我有用。

参考此链接 Display Keyboard for EditText in Emulator (GenyMotion) Android 4.3

答案 4 :(得分:0)

您可以使用此方法点击Edittextbox。

$Key       = ($_.Key | Out-String)