Java 如何在Editbox中添加带有文本的图像?
我试图在编辑框中添加带有一些文本的图像,但它没有显示图像。它只显示文本 这是我的xmlJava 如何在Editbox中添加带有文本的图像?,java,android,editbox,Java,Android,Editbox,我试图在编辑框中添加带有一些文本的图像,但它没有显示图像。它只显示文本 这是我的xml <Button android:id="@+id/favButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Add to " android:drawableRight="@drawable/white_star"
<Button
android:id="@+id/favButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add to "
android:drawableRight="@drawable/white_star"
android:layout_below="@id/priceText"
android:layout_alignParentLeft="true"
android:background="@drawable/rounded_corner_black"
android:padding="10dip"
style="@style/ButtonText"
android:onClick="onAddFavClick" />
你也可以这样试试
<EditText
android:drawableLeft="@drawable/your_image" />
或者作为参考,你可以
因此,您可以使用android:drawableRight=“您想要的功能称为
CompoundDrawable
您可以在EditText
中设置以下属性:
在您的例子中,当您想在右侧显示图像时,使用
android:drawableRight
如果您想继续使用XML,这是一种简单的方法
<RelativeLayout
android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/searchcards_back_relative" >
<ImageView
android:id="@+id/leftbutton"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:background="@drawable/searchleft"/>
<LinearLayout android:focusable="true"
android:id="@+id/searchcards_edit_search_lin"
android:focusableInTouchMode="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/leftbutton"
android:layout_centerHorizontal="true"
android:layout_marginLeft="0px"
android:background="@drawable/searchmiddle">
<EditText
android:hint="Search Cards"
android:id="@+id/searchcards_edit_search"
android:layout_width="fill_parent"
android:layout_height="28dp"
android:textColor="#000000"
android:textSize="18dp"
android:singleLine="true"
android:background="#0fff"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="21dp"
android:gravity="center_vertical"
android:layout_marginTop="0dp"
android:imeOptions="actionSearch"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<ImageView
android:id="@+id/rightbutton"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:background="@drawable/searchright"/>
<TextView
android:id="@+id/searchcards_back_hitsearch"
android:layout_width="35dp"
android:layout_height="40dp"
android:textSize="25px"
android:textStyle="bold"
android:layout_centerVertical="true"
android:textColor="@android:color/white"
android:layout_alignParentRight="true"
android:background="#0222"
android:text=""/>
</RelativeLayout>
<ListView
android:id="@+id/searchcards_list"
android:layout_width="wrap_content"
android:background="@drawable/background"
android:layout_height="fill_parent"
android:layout_below="@+id/edittext"
android:divider="#fff"
android:dividerHeight="1px"
android:cacheColorHint="@android:color/transparent"
android:layout_marginBottom="4px"
android:scrollbars="none" />
</RelativeLayout>
对于左、中、右图像,应使用drawable文件夹中的.png图像。
你也可以采取相对布局来做这件事。。。要了解更多信息,请继续用谷歌搜索…我只需使用以下方法即可获得图像
favButton.setCompoundDrawablesWithIntrinsicBounds( 0, 0,R.drawable.white_star, 0);
你是说用按钮编辑文本和u r???在xml中,这是什么。你想要编辑文本的圆角或其他一些东西。我正在使用按钮,但现在问题解决了。如果它对你有帮助,请接受我的答案…是的,我正在使用png图像。你得到答案了吗?是的,我得到了答案,我也在@Banku…:-)我做了,但它没有给我图像,这是我的问题。请再看一遍问题1。@AmitJayaswal发布输出图像和所需图像这就是我在回答中所说的,但您是通过编程实现的。
favButton.setCompoundDrawablesWithIntrinsicBounds( 0, 0,R.drawable.white_star, 0);