Android dialog activity frame as template - android

I've got a handful of configuration dialogs in my app, and they all have Cancel/OK buttons at the bottom. Now, in API level 11 and up, I want to show Cancel on the left and OK on the right, and also use the ButtonBar style. In API levels 10 and lower I want to show floating buttons, with OK on the left.
Presently I have copies of the XML layouts in both my layout and my layout-v11 folder, with nothing different between them but the button area. However these layouts are fairly complex and I'm trying to save some space, so it would really be better to just have one copy of each layout, and just snap the layouts into a template with the correct button style on the bottom. What would be the best way to go about this? Fragments?

Why not do just the button swap programatically? You can find the build version codes from SDK_INT and swap the PositiveButton and NegativeButton based on the SDK versions.
If you have the layouts in the xml files and cannot be done in the code for some reasons, you have just the buttons in two different layouts and use the merge tag

Related

How to design the button similar to compose button in Android gmail app

I need to design a button shown in this image. On click of the green button shown in the image few options should pop up. Can any one help me in doing this in Android application.
Use FloatingActionButton from android design support library:
https://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html
You will need to include this dependency in your apps build.gradle file to reference it:
com.android.support:design:22.2.0
Here's a great reference:
http://antonioleiva.com/floating-action-button/
You could do it without the design support lib - which would be a slightly more difficult approach. I don't like the design lib approach because it adds some unnecessary permissions to Android Manifest via the manifest merger, and adds bunch of code I don't need (and I can change the compile API level to whatever I want).
So, basically - you would need a layout container (i.e. a RelativeLayout), and inside it you would put your main layout (a toolbar, list, buttons, etc). Then, alongside those items, you can put a simple ImageView to the bottom right, but spaced a bit from screen edges. Then you can make a 9-patch with shadow included for its background, AND for API21+ you can create a circle shape drawable, and add some elevation to it (this will generate a shadow).
If you want it to move, fade out, fade in, etc. you will need to do these things manually, which makes it advanced in comparison to the design lib approach.

keeping tabs fixed on all screen of android development

I am new on android i am making an app having few tabs using fragment. Is there any way to keep tabs fixed on all screens or will I have to copy the code for tabs in all activities?
Simple way to do this is
Take linear layout at top & take relative layout for rest of the screen
Add number of tabs/buttons/imagebuttons you want
Apply listener for each button according to that button you can change the things which are in relative layout.
I think, this will be the simple & efficient way to handle the things.

Tips at start-up or update

I have an update for my app that includes ActionBarSherlock with a sliding menu. I have put my navigation entirely in to the sliding menu, leaving my main_activity pretty bare. I am worried the user won't know about the menu. So I want to add a prompt at start-up that will highlight the new feature. Like this:
I am not even sure what this is called, so I don't know how to research it. Any help or suggestions will be rewarded. Thanks!
You could just use overlay layout (Frame layout with multiple inner layouts will fit perfectly. Please note Frame Layout Z axis is by the lower the layout is in the xml, so the guide should be the last in the XML). Make that layout's background mostly transparent and add buttons and design to fit your needs. When you don't want to show the layout just set visibility to gone. And when you need it set to visible.

Tips on how to build a layout like this one

Could anyone give me a tip on how to build a layout like in the following picture?
The application i'm working on has absolutely nothing to do with VoIP but I'm trying to build something like this. One fixed toolbar at the bottom, an interchangeable middle pane with listviews, scrollviews or other, and another toolbar at the top which would change depending on the button selected on the bottom bar.
Also, would it be possible and good practice to keep all of this within a single activity?
You should NOT build an interface like this. Don't use bottom bars! Don't use labelled back buttons on action views!
You should read the Android design guidelines and then work with tab views... and other stuff referenced there and build an Android app.
Also, would it be possible and good practice to keep all of this within a single activity?
-Yes for sure, and yes with a slight catch, depending on what you mean.
One approach would be to create your top and bottom bars inside their own XML. Then in your activity onCreate() inflate and add at the top and bottom of your Layout.
If the bottom bar will not change ever, then you could actually add that into the layouts you already have. If you do it that way, to handle the listeners you could create an Activity that contains just the bottom bar click listeners and then extend that with all of your other activities.
Since the top bar can change though you'll probably have to inflate and add the views to that at run time, that way you can react to what is going on to add / remove / present the appropriate views in the top bar.
Also just because it is somewhat of a pet peeve of mine:
When designing your bottom bar please seriously consider the fact that some devices have soft buttons directly underneath the touch screen. And they are rather close to the screen on some devices. Applications with a bottom bar that is not tall enough create an opportunity for the user to hit one of the system buttons instead of one of the bottom bar buttons as they are intending (or vice versa). Which from a users perspective I must say is VERY aggravating.
Do not use bottom bars. To give a more familiar UI, put all of those functions into the top bar. Start by looking at the source code for the ActionBarCompat project in your android sdk sample folder.
The Android developer site is a good place to start. See
UI Guide
I also agree with the poster who recommended against this specific layout. It seems to have been developed for an iPhone and shouldn't be used "as is".

which one is better? -Creating buttons at Run time or design time in android

i need to create around 26 buttons for simple task like display alphabets. i can do this by using layout design.
if i create this button at run time will it give more performance(Considering memory, speed,apk size!)?
Important Requirements:
this layout will be used by 4 different activities.
I need to display 26 buttons at a time to user.
These button may contain background
image.
edit: This layout is like pop up window for other four activities. user can press any alphabets in this layout. As soon as alphabets get selected layout will be closed
Since everything is static residing in your assets, it is fine to have everything in xml files.
Still, one can argue that the 'notion' of parsing the xml layout files of your project introduces an overhead to the process of creating the views.
I would go with a well-designed layout defined in xml.
Yikes. While XML is the best practice answer, 26 of anything screams for some dynamic run-time creation, or at least a combination of the two. You're not going to see much difference in processing time or apk size either way - it will come down to code maintenance down the line.
For instance, consider what will happen when you want to change or add a new attribute, say padding, for each of your letter buttons. Do you want to have to manually go change all those XML elements, or think about a clever regex to properly find/replace?
I'd go with a combination of styles, <include> statement, and run time modification for a comprehensive, maintainable solution. First create a single button styled how you think you want all your buttons to look. Extract your "LetterButton" style out to style.xml and use the android:style="#style/LetterButton" attribute on your button instead. This will allow you to change your style in a single file and have it affect all your letter buttons.
Next, extract the button itself into an <include> file. You can do this by right clicking on the GUI version of the button and choosing "Extract include...". Then arrange your <include>-buttons however you need to, perhaps in a <TableLayout>. Make sure you give each one a unique id, like #+id/letter_button_0 up through _25. The text attribute for all these buttons can be anything, you'll set those dynamically later.
Finally, in your onCreate, define an array of ints of the form {R.id.letter_button_0, ...}, and an array of Strings of the form {"A", ...}, and iterate over those, doing a button = findbyId(int), button.setText(String) to put a letter on each of your buttons.
It may seem like more work this way, but you're doing all the heavy lifting creating a smart UI, so that down the line you can change code in a single place (style or include) and all your buttons will be updated.
Strongly recommend XML layouts for best practice and more understandable code. Also, If you are worried about performance for large view, use relative layouts, these are faster to render than other types of layouts such as LinearLayouts.
Showing XML is best practice:
http://developer.android.com/guide/topics/ui/declaring-layout.html
Also to increase performance keep the Buttons as Activity member variables, then they only need to be loaded once from resources.
Hope that helps,
Marc
You should create it at xml file and make visible and invisible as you need.
You could create a layout with having static assets in it & have dynamic text content & for dynamic backgrounds.You can have use the button properties of gone & visible in it.

Categories

Resources