Niko Gamulin
Niko Gamulin

Reputation: 66585

Android: How to Create a Custom button widget

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!

Upvotes: 3

Views: 15344

Answers (2)

leo
leo

Reputation: 135

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

see this Click Here

Upvotes: 7

AdamC
AdamC

Reputation: 16303

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.

Upvotes: 4

Related Questions