2017-02-26 147 views
1

我正在使用EditText。但光标始于屏幕中央。如果我在xml文件中使用wrap_content,我根本看不到EditText(它是隐藏的)。如何移动editText光标?

我希望光标和输入文本从顶部开始,位于我的工具栏下。有任何想法吗?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/activity_settings_contact_us" 
    android:orientation="vertical" 
    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="airjaw.butterflyandroid.SettingsContactUsActivity"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/my_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     android:elevation="4dp" 
     android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/editText" 
     /> 

    <Button 
     android:text="Send" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="15dp" 
     android:id="@+id/submitButton" 
     android:onClick="submitButtonPressed"/> 

</RelativeLayout> 

如何

enter image description here

+0

为您添加完整版式 –

回答

1

使用android:gravity="top"EditText里面,如果你只需要将光标移动到顶部

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/editText" 
    android:gravity="top" 
    /> 

编辑:使用android:layout_marginTop="?attr/actionBarSize"如果有任何重叠或没有,你甚至可以使用android:layout_below="@+id/my_toolbar"

编辑2:在您的根布局中使用android:fitsSystemWindows="true,其中@id activity_settings_contact_us并在您的活动标签@ manifest下使用android:windowSoftInputMode="adjustResize"!这是给你的最后一个问题在评论

+0

不幸的是,与我的工具栏重叠,我看不到文字。 – makthrow

+0

@makthrow然后使用'?attr/actionBarSize'将工具栏的高度添加到您的编辑文本视图中。 –

+0

@makthrow现在是怎么样了^ _^ –

0

更改了android:宽度为DP值。例如,

<EditText 
    android:layout_width="320dp" 
    android:layout_height="match_parent" 
    android:id="@+id/myEditText1" /> 
+0

不适用于我。看不到我输入的文字。 – makthrow

0

尝试使用LinearLayout而不是RelativeLayout。