android - 如何在 EditText 中放置按钮

标签 android android-layout android-edittext imagebutton

我想在 EditText 中放置一个图像按钮,但我没有 Idea 请告诉我如何操作,如图所示。谢谢

enter image description here

最佳答案

如果您不想点击该图像,那么您可以使用 EditText 的 drawableRight 属性..

android:drawableRight="@drawable/icon"

如果你想点击然后使用下面的代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter search key" />

    <ImageButton
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:src="@drawable/search"
        android:layout_centerVertical="true"
        android:layout_margin="5dp"
        android:text="Button"/>

</RelativeLayout>

关于android - 如何在 EditText 中放置按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13151366/

相关文章:

android - 如何在我的自定义 styles.xml 中继承默认的 Android 样式?

java - 获取用户在 TextView 中设置的 Short 值

android - Android 上的 Facebook SDK

android - 插入失败时获取约束错误

java - android-想要将 Button 放在 listview 之上

java - 框架布局 : How to add other Views on top of GLSurfaceView?

android - 方向更改后如何将光标移动到 EditText 行的末尾?

android - 如何在没有键盘的情况下显示Android模拟器

java - 在 Android/Java 中实现类 C# 事件

android - ListView 下方的页脚固定在屏幕底部