【发布时间】:2014-07-07 12:46:04
【问题描述】:
如何创建这样的按钮?
我想稍后在应用程序中以编程方式更改文本数量。
【问题讨论】:
-
你能发一些代码吗?
-
您可以使用
TextView。它是可点击的。它可以包含动态文本。它可以有背景,而不使用按钮的默认背景。
标签: android image button background
如何创建这样的按钮?
我想稍后在应用程序中以编程方式更改文本数量。
【问题讨论】:
TextView。它是可点击的。它可以包含动态文本。它可以有背景,而不使用按钮的默认背景。
标签: android image button background
创建该背景的图像并获取一个文本视图,将其背景设置为此图像并设置您想要设置的任何文本。
例如你的这个图片名称是 abc.png
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/abc"
android:text="1" />
设置动态值可以使用TextView的setText方法
【讨论】:
您可以创建一个包含您的图像和文本的布局(例如 framelayout),并在该布局上添加一个侦听器
<FrameLayout
android:id="@+id/my_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_image"/>
<TextView
android:id="@+id/my_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
(TextView) findViewById(R.id.my_text).setText("HELLO");
findViewById(R.id.my_layout).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Action on click
}
});
希望对你有帮助!
【讨论】:
在您的 Button XML 代码中使用此属性。
android:background="@android:color/transparent"
android:drawableTop="@drawable/[your background image here]"
【讨论】:
你应该在这里使用 Textview:
像这样设置TextView的属性:
android:padding_left="20dp"
android:poadding_right="20dp"
android:padding_top="5dp"
android:padding_bottom="5dp"
android:textColor="#000000"
android:backgroundColor="#FFFFFF"
android:clickable="true"
android:textSize="22sp"
【讨论】: