如何让 Edittext(多行)在顶部位置可绘制
How to get Edittext(Multiline) leftdrawable on top position
我正在使用具有 textMultiLine
属性的 Edittext
。我使用 android:gravity="top"
在顶部位置获得了 edittext 文本。但是我无法获得 android:drawableLeft="@drawable/ic_message"
的最高位置。
我想要 android:drawableLeft="@drawable/ic_message"
在顶部位置(消息 文本的左侧)
编辑
我的Edittext
xml如下:
<EditText
android:id="@+id/edtContactMessage"
style="@style/styleRoundedEdittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/tendp"
android:drawableLeft="@drawable/ic_message"
android:gravity="top"
android:hint="@string/strMessage"
android:imeOptions="actionDone"
android:inputType="textMultiLine"
android:lines="5"
android:maxLength="500"
android:minHeight="120dp"
android:scrollbars="vertical"
android:singleLine="false" />
你可以这样做:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
**<!-- Edit text with drawable at top left -->**
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/image">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edit"
android:hint="Enter text"
android:maxLines="10"
android:inputType="textMultiLine" />
</FrameLayout>
</RelativeLayout>
希望对您有所帮助。
无法像这样在顶部位置的 EditText 上设置左侧可绘制对象,您需要将 EditText 包装在父布局中,您可以在父布局中放置一个在该位置绘制图标的 ImageView。
这是一个例子:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@android:drawable/edit_text"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/ic_menu_send"
android:scaleType="fitStart"
android:contentDescription="message icon"
/>
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@null"
android:padding="4dp"
android:text="Message"
android:inputType="textMultiLine"
android:gravity="top"
android:layout_weight="1" />
</LinearLayout>
根据 TouchBoarder 的回答,我在顶部位置获得了 Edittext(Multiline) leftdrawable :)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/rounded_edittext"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="message icon"
android:paddingBottom="@dimen/tendp"
android:paddingLeft="@dimen/tendp"
android:paddingTop="@dimen/tendp"
android:scaleType="fitStart"
android:src="@drawable/ic_message" />
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null"
android:gravity="top"
android:inputType="textMultiLine"
android:padding="4dp"
android:text="Message" />
</LinearLayout>
输出:
我正在使用具有 textMultiLine
属性的 Edittext
。我使用 android:gravity="top"
在顶部位置获得了 edittext 文本。但是我无法获得 android:drawableLeft="@drawable/ic_message"
的最高位置。
我想要 android:drawableLeft="@drawable/ic_message"
在顶部位置(消息 文本的左侧)
编辑
我的Edittext
xml如下:
<EditText
android:id="@+id/edtContactMessage"
style="@style/styleRoundedEdittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/tendp"
android:drawableLeft="@drawable/ic_message"
android:gravity="top"
android:hint="@string/strMessage"
android:imeOptions="actionDone"
android:inputType="textMultiLine"
android:lines="5"
android:maxLength="500"
android:minHeight="120dp"
android:scrollbars="vertical"
android:singleLine="false" />
你可以这样做:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
**<!-- Edit text with drawable at top left -->**
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/image">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edit"
android:hint="Enter text"
android:maxLines="10"
android:inputType="textMultiLine" />
</FrameLayout>
</RelativeLayout>
希望对您有所帮助。
无法像这样在顶部位置的 EditText 上设置左侧可绘制对象,您需要将 EditText 包装在父布局中,您可以在父布局中放置一个在该位置绘制图标的 ImageView。
这是一个例子:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@android:drawable/edit_text"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/ic_menu_send"
android:scaleType="fitStart"
android:contentDescription="message icon"
/>
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@null"
android:padding="4dp"
android:text="Message"
android:inputType="textMultiLine"
android:gravity="top"
android:layout_weight="1" />
</LinearLayout>
根据 TouchBoarder 的回答,我在顶部位置获得了 Edittext(Multiline) leftdrawable :)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/rounded_edittext"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="message icon"
android:paddingBottom="@dimen/tendp"
android:paddingLeft="@dimen/tendp"
android:paddingTop="@dimen/tendp"
android:scaleType="fitStart"
android:src="@drawable/ic_message" />
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null"
android:gravity="top"
android:inputType="textMultiLine"
android:padding="4dp"
android:text="Message" />
</LinearLayout>
输出: