Which Android control to use?
I'm taking my first steps in Android programming.
My application is to create entries in a database. For this task I have created a new Activity. All is fine - but I don't really like how it looks.
Currently, the emulator shows this:
I'd like to have something similar to the "New Contact" Activity:
- Buttons at the bottom of the window, not directly below the other controls (I'll hopefully figure that out myself)
- Buttons within a nice "box" like shown in the screenshot (what's the control hosting the buttons here?)
- When soft-keyboard is displayed, the buttons should "move up". If there's not enough room, the entire area should be scrollable (I'll try and figure that out myself too)
Which control hosts the buttons in the above "New contact" screenshot? I'd like to use the same for my buttons.
Asked by: Audrey367 | Posted: 20-01-2022
Answer 1
One way to figure out what an existing activity does is to use hierarchyviewer
and examine the activity's contents.
Another way to figure out what a native Android activity does is to look at the source code. In this case, it would appear that the buttons are inside of a horizontal LinearLayout
with style="@android:style/ButtonBar"
to give the silver sheen. That style, in turn, uses @android:drawable/bottom_bar
as its background. That image can be found in your SDK installation -- go to the platform directory of your choice, then data/res/drawable-hdpi
and data/res/drawable-mdpi
for the two versions.
Answer 2
The contacts layout looks like a ListView sitting on top of some sort of RelativeLayout or LinearLayout housing the buttons. The silver background may simply have been set using android:background on the Layout itself (layouts are views).
I found that the commonsware books are excellent resources for getting started and have good examples for this type of layout.
Answered by: Grace477 | Posted: 21-02-2022Answer 3
Hey, this is a little late, and I know you've already got the silver bar you wanted, which is all good, but I've stumbled upon a really good guide on controlling the soft keyboard for best user experience. It covers, among other things, how to make the visible area resize to fit the button bar in the view while typing, which is done by specifying the activity in the manifest file like so:
<activity android:name=".MyActivity" android:windowSoftInputMode="resize" />
I really recommend reading it, it covers a lot more helpful stuff than just that. Hope that helps; I couldn't see that anyone else has answered that particular part of your question.
Answered by: Melissa418 | Posted: 21-02-2022Answer 4
You can put them in LinearLayout and assign weight of 1 to each of the buttons. Also if you own dev phone / or want to see UI of the application in emulator - there is a very cool tool call hierarchyviewer http://developer.android.com/guide/developing/tools/hierarchy-viewer.html and you can see how UI of app you like has been laydown.
Answered by: David431 | Posted: 21-02-2022Similar questions
android - Which control would be a better fit to this problem?
Requirement:
I have a GridView of thumbnails; the user can click on a thumbnail to view the larger, full sized image. This "full sized" image is to be fetched from a remote server. When the user is viewing a particular image he should be able to cycle through all of them by swiping his fingers on the screen(like leafing through pages of a book).
Questions:
1. What component should be used to di...
Android 3G/2G control API?
On Android settings, under Wireless controls->Mobile networks there is a setting "Use only 2G networks".
In the Android SDK reference, under android.telephony.TelephonyManager, there doesn't seem to be anything to control the network type.
What APIs does this setting actually call?
Android game loop, how to control speed and frame rate
I've written a game for Android, and I've tested it on the Dev Phone 1. It works perfectly, the speed is just right. However, I'm sure phone CPU's are getting faster. They may already be faster than the dev phone.
How do I make sure that my game runs at the exact same speed no matter what the device or how fast it runs? Do you know of any techniques? Should I check some kind of timer at the top of the loop eac...
android - digital compass problem
I am creating an augmented reality application and I noticed that the stored locations don't appear appear on the correct direction if I try to use the camera view (using layar or wikitude API).
The problem is that the digital compass doesn't show north correctly when you try to look at the known objects through the camera view. If align the phone with the ground (look at my shoes) the locations appear at the screen accord...
android - How to remove labels from a MapView?
I am trying to make a satellite view (via a MapView) without labels. How can I do this?
android - Custom title with image
i'm creating custom title for activity by disabling standard one and managing everything myself. I wonder if it's possible to replace/theme standart title to my needs.
I can customize size, background image, and text via themes by changing windowXYZStyle items.
The only thing i couldn't find - how i can add image instead of text.
I've tried requestWindowFeature(Window.FEATURE_CUSTOM_TITLE)
and ...
canvas - Android draw with blur
I need do draw on Android's Canvas using Blur effect,
it is a very simple feature,
I need to draw a circular area, which is blurred (the foreground) and the background transparent, I can do everything with manipulating the colour alpha to do it with custom transparency but I need it to be blurred instead of transparent..
any ideas?
layout - How to resize a android webview after adding data in it
In a layout (linear, vertical) hierarchy I've got several views and one of them is a WebView.
They all have same parameters:
android:layout_width="fill_parent"
android:layout_height="wrap_content"
For all views, the spacing between elements is correctly handled but for the Webview there is a lot of spaces after the displayed text inside.
I set the (HTML) text of the webview in the ...
How to find easily the source of an android class
I know I can access android source code from https://android.googlesource.com, but it's hard to select the right git repo if I only know the package and the name of an android class.
Isn't there a way to locate a file in https://android.googlesource.com?
camera - Android Intent Save Path
At the moment I am using two intents. One for voice-recording, another for the camera:
Intent photoIntent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(photoIntent, ACTIVITY_TAKE_PHOTO);
Intent voiceIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(voiceIntent, ACTIVITY_RECORD_SOUND);
My aim is to put an Extra to each of t...
Android "hover" event in custom layout
I have a custom layout that I have written that basically just displays a bunch of ImageViews. I am handing onTouch events for all the ImageViews in my layout.
However, if a user touches one imageView and then drags over another ImageView, I would like to be able to handle that as well.
How would I go about capturing this behaviour?
android - What is the ideal place to cache images?
I am fetching a lot of thumbnails in my application from a remote server and lazy-loading these in a list view.
The image fetches run in a background AsynTask and when completed the fetched images are stored in a HashMap using SoftReferences.
This works just fine but when the images in the cache gets GC’d, the fetches have to be rerun.
I could have stored them on the SD card so there would be no...
How to create a tree view in Android?
There are no controls in Android that provide Tree-like View. There is an ExpandableList View which I suspect could be used to creating one.
Have you tried imlpementing such a control?
How would one implement such a control in Android?
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android