views:

139

answers:

3

Hi there!

In some apps I see an EditText widget combined with a Button on the right side (e.g. the search field in the twitter app). How can I create a widget like that?

Regards, Marco

+1  A: 

Check out the TableLayout and the RelativeLayout in the Android developer center.

There are a few more official tutorials on layouts here.

If you use the TableLayout, you can put an EditText in the left column of a two column layout, and then put the button on the right. Or, probably a better way, would be to use a RelativeLayout, which gives you a little more flexibility.

Ryan Hayes
Sorry, I think my explenation wasn't precise enough :)I'm already using a RelativeLayout and the button is already next to the EditText. What is important to me, is that it should look as if the button was "in" the EditText (see link to twitter app).
Marco
Oh, I see now. It looks like the button is actually an image, with rounded corners on the right side and square on the left, and that the EditText is the standard one with the right side corners squared. Then they're just smashed up against each other with no margins. The first thing to look for is probably how to square the corners of an EditText and then make an image that looks like the search button (which would include the groove around the edges that makes it look like it's cut out like a button. Then just make them the same size and put them together.
Ryan Hayes
Thanks a lot! Didn't even think about the button being an image :D
Marco
A: 

Take a look at Applying Styles and Themes and the Draw 9-patch tool. 9-patches are used as the background for widgets like EditText and Button. You can combine a custom widget background with padding and margins to get the effect you want.

adamp
A: 

I finally found a solution. Here's how the google guys did it: search_bar.xml Thanks for your help!

Marco