Native dialogs in Android are boring! if you are developing an app having some cool and customized theme then doing something about those dull dialogs is a must. They wouldn’t just compliment the overall look of your application. I faced this kinda scenario recently and while experimenting and trying different suggestions on forums, I finally got around it and made it to work!
First things first, as far as my experience went, AlertDialog is not going to help you here. It just don’t get rid of that black background that is there by default (talking about gingerbread dialogs here). No matter what you do, it’ll always show the black background from behind your image (if you have any). Anyways, to create a custom dialog, we need to create a layout first in a separate xml file. Here’s an example:
This is just a simple layout having a background image that has irregular borders. Now we just need to write a few lines of code in order to make it work:
Here, we are setting the background color to transparent in order to get rid of the default dialog background color. After that, we just need to assign the layout resource to the dialog and that gets the job done.
Notice the resultDlg.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); This will remove the dim effect that makes your parent layout a bit darker. You can also set some additional flags like adding a blurred effect to the background/host activity from which this dialog is invoked. To do this, simply use the addFlags function with FLAG_BLUR_BEHIND flag. Here’s the exact statement:
This will create a very nice blur effect which I find more neat than the original dim effect. And that ends this post here. Feel free to comment and ask questions, I’ll try to answer them as swiftly as I can.
Quite a long title, isn’t it?
On-screen keyboard usually takes around half of the screen space while it’s shown. Most of the times it hides important controls/views that you want to be shown to the user all the times. Consider a layout having a EditText widget at the top, a list or some other control in the middle and some Buttons right at the bottom. While the user is writing text in the EditText view through on-screen keyboard, the buttons would be hiding behind it. Luckily, Android has an option to handle this scenario automatically without writing much code.
To enable a layout to adjust itself while the keyboard is shown, you need to configure an attribute for its host activity through AndroidManifest.xml file. Here’s how to do it:
<activity android:name="TestActivity" android:windowSoftInputMode="adjustResize" android:screenOrientation="portrait">
By setting android:windowSoftinputMode of this activity to adjustResize you are telling it to resize itself while the on-screen keyboard is shown. This will let the activity to shorten it’s layout in order to show everything that’s present over it. For example, if you have some buttons at the bottom of the screen, this setting will show them just above the keyboard helping the user to interact with them without closing the keyboard.
There’s one important catch in this however, this configuration DOES NOT work if the application is bound to run in full-screen. This is normally done by setting it’s android:theme attribute to @android:style/Theme.NoTitleBar.FullScreen in AndroidManifest.xml file.
This is one simple and neat technique to make your layout more flexible and user-friendly.
Recently, we at excelarz Interactive made a series of Sports Apps that enables user to follow their choice of sports in an intuitive and flexible manner. The set of applications offers its user to view news, live scores, blogs, players, schedule, draws, twitter feeds according to his choice. What we needed was to build the apps in a way as to enhance the usabilty by letting the user customize the application in a way that he choses.
For implementing the switching between selected information types (news, blogs, scores, players, twitter, schedule etc), we first looked into the native tab control of Android. After digging enough, we concluded that the tab control would not help us accomplish this variable nature that we required from it due to its rigid set of options and properties.
We then came up with the idea of using the Gallery view for achieving this functionality. What we do is we make some images for each of the tab that we require to have in our application. Then a simple adapter is created (which is required to populate the gallery dynamically) and pass on the list of selected tabs to the adapter. The adapter then creates the view as per the selection made by the user. This way we managed to acheive a sliding choice bar for selection of different info type.
See the tab bar in action the the following video.
This approach may definity not the ideal one in this scenario but we did achieve what we wanted to do. Any suggestion on improvements and alternative is more than welcome.
Here’s a quick post that will guide you through a few very simple ways through which you can make you application run in a full screen i.e. without title and the notification bar of the Android OS.
1. You can add the following piece of code to your OnCreate function of your activity to make it run in full screen mode:
Note that the first call to requestWindowFeature function might be optional for you in case you want to run the application in full screen but you also need to show the title.
2. The second method, which is more preferred in my opinion, is to use the AndroidManifest.xml file and add following attribute to your activity (in your <activity> tag, of-course):
The main difference between these two methods is that the first one will be called a bit late and you will see the notification bar appearing and then going in the background. The second method however avoids this behavior and make your application run in full screen straight away.