3

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

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">

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?

I would really appreciate your help.

Thanks!

1
  • Hi Niko, How did you solve this task? Could you please share the code, as i too have similar requirement. Commented Sep 28, 2010 at 6:47

2 Answers 2

7

Hey, To create a circular button or rectangular button you can use shape. It can be done in .xml file.

see this Click Here

Sign up to request clarification or add additional context in comments.

Comments

4

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.

1 Comment

When you extend the view Class, you'll need to override onDraw and the key handling functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.