Official website for Linux User & Developer
FOLLOW US ON:
Jul
21

Android Development masterclass

by Kunal Deo

It’s time to go beyond the ‘hello world’ app. Let’s look into real-world situations and start doing big things with your Android development project…

The Android platform itself takes care of this for the most part, optimising your application display for the current screen size, such as scaling the application resources and layout to adapt the display. However, you may want to have fine control on how your application displays on multiple devices. You can do that as well.  You can use the attributes of the manifest element <supports-screens>  to explicitly specify the supported screen sizes.

Syntax:

&lt;supports-screens android:smallScreens=[“true” | “false”]
 android:normalScreens=[“true” | “false”]
 android:largeScreens=[“true” | “false”]
 android:anyDensity=[“true” | “false”] /&gt;

You can also use the resource directory qualifiers for the screen size and density. This helps you ship a separate optimised UI for each supported screen size.
For example:

res/layout/my_layout.xml            // layout for normal screen size
res/layout-small/my_layout.xml      // layout for small screen size
res/layout-large/my_layout.xml      // layout for large screen size
res/layout-large-land/my_layout.xml // layout for large screen size in landscape mode

res/drawable-ldpi/my_icon.png       // icon image for low density
res/drawable-mdpi/dpi/my_icon.png   // icon for medium density
res/drawable-hdpi/my_icon.png       // icon image for high density
res/drawable-nodpi/composite.xml    // density independent resource<!--nextpage--->

Creating alert dialogs
Alert messages are useful for asking for user confirmations or providing important information. You can use the AlertDialog class to display alerts. AlertDialog supports one, two or three buttons. In case you want to display just the string in this dialog box, you can use the setMessage() method.
For example:
@code

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;

public class MainActivity extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 AlertDialog alertDialog = new  AlertDialog.Builder(MainActivity.this).create();
 alertDialog.setTitle(“LUD Subscription Expired”);
 alertDialog.setMessage(“Your subscription to LUD magazine has expired. Renew ?”);

 alertDialog.setButton(“Yes”, new DialogInterface.OnClickListener() {
 public void onClick(DialogInterface dialog, int which) {

 //here you can add functions

 } });  

 alertDialog.setIcon(R.drawable.icon);
 alertDialog.show();

 }
}        

 alertDialog.setIcon(R.drawable.icon);
 alertDialog.show();
twitter follow us
Pages: 1 2 3 4 5 6
  • Tell a Friend
  • Follow our Twitter to find out about all the latest Linux news, reviews, previews, interviews, features and a whole more.

    One Comment »

    What's your opinion?

    Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

    Be nice. Keep it clean. Stay on topic. No spam.

    * Required fields