如何获得Edittext(Multiline)在顶部位置可左绘制 [英] How to get Edittext(Multiline) leftdrawable on top position

查看:87
本文介绍了如何获得Edittext(Multiline)在顶部位置可左绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 Edittext textMultiLine 属性一起使用.我使用 android:gravity ="top" 在最高位置获得了edittext文本.但是我无法在最高位置获得 android:drawableLeft ="@ drawable/ic_message" .

I am using Edittext with textMultiLine attributes. I got edittext text on top position using android:gravity="top". But I cannot get android:drawableLeft="@drawable/ic_message" on top position.

我想要 android:drawableLeft ="@ drawable/ic_message" 放在顶部位置(消息文本的左侧)

I want android:drawableLeft="@drawable/ic_message" on top position(left of the Message text)

编辑

我的 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" />

推荐答案

无法在这样的顶部位置在EditText上设置左可绘制对象,您需要将EditText包装在父版式中,您可以在其中在该位置放置一个ImageView来绘制图标.

It is not possible to set the left drawable on a EditText at the top position like that, you would need to wrap your EditText inside a parent layout where you can place a ImageView that draws the icon at this position instead.

这里是一个例子:

<?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>

这篇关于如何获得Edittext(Multiline)在顶部位置可左绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆