programming4us
programming4us
MOBILE

Adding the Android CSS

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
9/23/2010 11:39:21 AM
There are a number of UI conventions that make an Android app look like an Android app. In the next section, we’ll add the distinctive title bar, lists with rounded corners, finger-friendly links that look like glossy buttons, etc. With the text editor of your choice, create a file named android.css and add the code shown in Example 1 to it, then save the file in the same directory as your HTML document.
Example 1. Setting some general site-wide styles on the HTML body element
body {
background-color: #ddd; /* Background color */
color: #222; /* Foreground color used for text */
font-family: Helvetica;
font-size: 14px;
margin: 0; /* Amount of negative space around the
outside of the body */
padding: 0; /* Amount of negative space around the
inside of the body */
}


Tip: All text on Android is rendered using a custom font named Droid. The Droid font family was specifically built for mobile devices, has excellent character set support, and contains three variants: Droid Sans, Droid Sans Mono, and Droid Serif. Therefore, specifying a font family of Helvetica as we’ve done here will only have an effect on devices other than Android.

Now let’s attack the header div that contains the main home link (i.e., the logo link) and the primary and secondary site navigation. The first step is to format the logo link as a clickable title bar. Add the following to the android.css file:

#header h1 {
margin: 0;
padding: 0;
}
#header h1 a {
background-color: #ccc;
border-bottom: 1px solid #666;
color: #222;
display: block;
font-size: 20px;
font-weight: bold;
padding: 10px 0;
text-align: center;
text-decoration: none;
}

We’ll format the primary and secondary navigation ul blocks identically, so we can just use the generic tag selectors (i.e., #header ul) as opposed to the tag IDs (i.e., #header ul#utility, #header ul#nav):

#header ul {
list-style: none;
margin: 10px;
padding: 0;
}
#header ul li a {
background-color: #FFFFFF;
border: 1px solid #999999;
color: #222222;
display: block;
font-size: 17px;
font-weight: bold;
margin-bottom: -1px;
padding: 12px 10px;
text-decoration: none;
}

Pretty simple so far, right? With this little bit of CSS, we have already made a big improvement on the Android page design (Figure 1). Next, add some padding to the content and sidebar divs to indent the text from the edge of the screen a bit (Figure 2):

#content, #sidebar {
padding: 10px;
}


Tip: You might be wondering why we’re adding padding to the content and sidebar elements instead of setting it globally on the body element itself. The reason is that it’s very common to have elements displayed edge to edge (as with the header in this example). Because of this, padding applied to the body or some other element that’s wrapped around lots of others can become more trouble than it’s worth.
Figure 1. A little bit of CSS can go a long way toward enhancing the usability of your Android app


Figure 2. Indenting text from the edges


The content in the footer of this page is basically a rehash of the navigation element (the ul element with the ID nav) at the top of the page, so you can remove the footer from the Android version of the page by setting the display to none, as follows:

#footer {
display: none;
}

Other  
 
programming4us
 
 
programming4us