Android的:如何创建自定义按钮控件 [英] Android: How to Create a Custom button widget

查看:135
本文介绍了Android的:如何创建自定义按钮控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建具有圆形或矩形背景,文字及以下或上面的文字图像的按钮。

I would like to create a button with circular or rectangular background, text and an image below or above the text.

下面是的CustomButton布局,我添加了对象(背景和文本 - ImageView的缺失):

Here is the CustomButton Layout where I added the objects (background and text - ImageView is missing):

<FrameLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_height="wrap_content"
 android:orientation="horizontal" android:layout_width="wrap_content" android:layout_gravity="center_vertical|center_horizontal">

我想创建一个方法的CustomButton对象的setText()和setImage(),这将改变按钮上的文字和图像,并把多个CustomButtons为主要布局。

I would like to create a CustomButton object with methods setText() and setImage() which would change the button text and image and place multiple CustomButtons into main layout.

有谁知道如何创建一个自定义布局,将其放入另一个布局(主)和修改活动的元素这势必将主要布局?

Does anyone know how to create a custom layout, place it into another layout(main) and modify its elements from the activity which is bound to main layout?

我真的AP preciate你的帮助。

I would really appreciate your help.

谢谢!

推荐答案

如果你想编程访问,你应该继承观,做在java中你在那里工作。你仍然可以做布局,XML,但是有你想要的图片和文字的方法。然后,您就可以使用这个在另一个布局放置CustomButtons。

If you want programmatic access, you should subclass View and do your work there in java. You can still do the layout in xml, but have the image and text methods that you want. You will then be able to use this in another layout to place your CustomButtons.

这篇关于Android的:如何创建自定义按钮控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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