Câu trả lời:
Sử dụng android:drawableLefttài sản trên EditText.
<EditText
...
android:drawableLeft="@drawable/my_icon" />
drawablePaddingtài sản.
Bạn có thể đặt drawableLeft trong XML theo đề xuất của marcos , nhưng bạn cũng có thể muốn đặt nó theo chương trình - ví dụ như để đáp ứng với một sự kiện. Để thực hiện việc này, hãy sử dụng phương thức setCompoundDrawablesWithIntrincisBound (int, int, int, int) :
EditText editText = findViewById(R.id.myEditText);
// Set drawables for left, top, right, and bottom - send 0 for nothing
editTxt.setCompoundDrawablesWithIntrinsicBounds(R.drawable.myDrawable, 0, 0, 0);
nullkhi chế độ xem được nhấp.
Nếu bạn muốn sử dụng drawable mặc định của Android, bạn có thể sử dụng @android:drawable/ic_menu_searchnhư thế này:
<EditText android:id="@+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/ic_menu_search"
android:hint="Search product.."
android:inputType="textVisiblePassword"/>
Sử dụng :
<EditText
..
android:drawableStart="@drawable/icon" />
sử dụng android: drawbleStart thích hợp trên EditText
<EditText
...
android:drawableStart="@drawable/my_icon" />
Sử dụng bố cục tương đối và đặt nút ở vị trí bên trái của chế độ xem văn bản chỉnh sửa và đặt phần đệm bên trái của chế độ xem văn bản của bạn theo kích thước của nút. Tôi không thể nghĩ ra một cách hay để làm điều đó mà không khó mã hóa phần đệm: /
Bạn cũng có thể sử dụng công cụ apk để sắp xếp giải nén apk facebook và xem các tệp bố cục của nó.