【问题标题】:EditText's hint gets cut off because my hint text is longer than one line. The editText only displays one line. How can I make the whole hint visible?EditText 的提示被切断,因为我的提示文本超过一行。 editText 只显示一行。如何使整个提示可见?
【发布时间】:2014-07-24 19:08:00
【问题描述】:

EditText 的提示被截断,因为我的提示文本超过了一行。 editText 只显示一行。如何使整个提示可见?

这是给我带来麻烦的editText。

<EditText android:id="@+id/pin" 
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:inputType="number"
         android:hint="@string/pinhintadmin"
         android:maxLength="4"
         android:layout_margin="10dip"
         android:layout_marginBottom="20dip"/>

这是我的整个 xml 文件。

<LinearLayout 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:orientation="vertical"
    android:background="@drawable/background1" >  
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
        <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" > 

            <TextView android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="@string/burr"
         android:textStyle="bold"
         android:layout_marginLeft="10dip"
         android:layout_marginRight="10dip"
         android:layout_marginTop="20dip"/>

    <EditText android:id="@+id/flob" 
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:hint="@string/buildingnameandaddress"
         android:inputType="textCapWords"
         android:layout_margin="10dip"
         android:layout_marginBottom="20dip"/>


     <TextView android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="@string/appartment"
         android:textStyle="bold"
         android:layout_marginLeft="10dip"
         android:layout_marginRight="10dip"
         android:layout_marginTop="20dip"/>

     <EditText android:id="@+id/txtName" 
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:hint="@string/hintapp"
         android:layout_margin="10dip"
         android:inputType="textCapSentences"
         android:layout_marginBottom="20dip"/>
     <TextView android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="Pin:"
         android:textStyle="bold"
         android:layout_marginLeft="10dip"
         android:layout_marginRight="10dip"
         android:layout_marginTop="20dip"/>

     <EditText android:id="@+id/pin" 
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:inputType="number"
         android:hint="@string/pinhintadmin"
         android:maxLength="4"
         android:layout_margin="10dip"
         android:layout_marginBottom="20dip"/>

     <TextView android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="@string/username"
         android:textStyle="bold"
         android:layout_marginLeft="10dip"
         android:layout_marginRight="10dip"/>

     <EditText android:id="@+id/txtEmail" 
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:inputType="textCapWords"
         android:layout_margin="10dip"
         android:layout_marginBottom="20dip"/>
     <TextView android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="@string/password"
         android:textStyle="bold"
         android:layout_marginLeft="10dip"
         android:layout_marginRight="10dip"
         android:layout_marginTop="20dip"/>

     <EditText android:id="@+id/registerPassword" 
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_margin="10dip"
         android:layout_marginBottom="20dip"/>
      <Button
        android:id="@+id/btnRegister"
        android:text="@string/registerbtnadmin"
       android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dip"
        android:textStyle="bold" 
        android:background="@drawable/button_red"
         android:textColor="@drawable/button_text_color" />

     <!--  Error message -->
        <TextView android:id="@+id/register_error"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:textColor="#e30000"
                    android:padding="10dip"
                    android:textStyle="bold"/>
     </LinearLayout>
     </ScrollView>

</LinearLayout>

【问题讨论】:

  • 什么是@string/pinhintadmin?
  • 有些长,大约需要两行。这不是很相关,不是英文,只是一个随机字符串,没什么特别的。

标签: android xml android-edittext


【解决方案1】:

你可以试试

android:scrollHorizontally="true"

参考here

或者 你可以试试这个

view.setHint(Html.fromHtml("<small><small><small>" + 
         getString(R.string.hint) + "</small></small></small>"));

作为接受的答案here

【讨论】:

  • 那行不通。我猜它适用于文本很长的情况,但我的文本不长,只是提示很长。
【解决方案2】:

在您的 XML 中添加 android:inputType="textMultiLine"

<EditText
    android:inputType="textMultiLine" 
    style="@style/TextAppearance.AppCompat.Small"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:autofillHints="personName"
    android:background="@null"
    android:hint="Enter first name"
    android:maxLength="25"/>

【讨论】:

    【解决方案3】:

    如果您有很长的字符串作为 eddittext 的提示,您可以将 new line character 放在新行出现的位置

    样本:

     android:hint="first line \n second line"
    

    【讨论】:

    • 我可以这样做,但我不确定在哪里输入换行符,对于较小的屏幕它会过早断开,而对于较大的屏幕则过晚。我想我可以放弃长提示。
    • @JeromeWasBannedBySONazis 使用您的 values 文件夹。适用于较小的屏幕和较大的屏幕。
    【解决方案4】:

    尝试在字符串中使用\n&lt;string name="pinhintadmin"&gt;line one \n line two &lt;/string&gt;

    或尝试使用android:scrollHorizontally="true"

    【讨论】:

      猜你喜欢
      • 2011-04-06
      • 1970-01-01
      • 2016-03-30
      • 2013-06-29
      • 1970-01-01
      • 2015-02-21
      • 2013-04-14
      • 1970-01-01
      相关资源
      最近更新 更多