SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
Android UI Reference
            By
       Matthew Gaunt
Who? What? Why?
 Hi, I’m Matt Gaunt (@gauntface) I’ve been developing on Android, on and off, for the past 2
                            years (starting from the 0.9 SDK).

The reason I’ve put this document together is to help others with things I struggled with when
I first started out, to help others learn new things with Android UI and to inform people about
                            some of the new Android design patterns.

  This presentation will be suitable for learning, for reference and also great for people just
                           wondering what Android UI is all about.

                If you spot something wrong or disagree, then let me know :)



                            E-mail Address: matt@gauntface.co.uk
What Google Want - Dashboard
  Lets start off with what Google want
            developers to do.

             The Dashboard

  This is a nice simple, clean and frankly
      easy to follow design pattern.

Have a panel with 4 - 6 of your app’s main
                functions.

Example Apps: Twitter, Facebook, Google
                Places

Note: You don’t have to open your app on
               this screen
What Google Want - Action Bar
                The Action Bar

 One thing many dev’s do, is needlessy fill the
screen, removing the notification bar from the
                     UI.

The only reason I can think of why someone
  might do this, is to get rid of the, not so
              pretty, title bar.

Instead Google are recommending the Action
 Bar. The logo on the right should link to the
   dashboard and the left side should have
  buttons relevant to that activity - Perfect :)

Examples - Facebook, Twitter and many more
What Google Want - Quick Action
                        The Quick Action

            This one I have some reservations about.

   It’s a very kool and fun way to give extra functionality in an
intuitive way, especially for specific elements on screen (i.e. a list
                 item or for displaying extra info).

The issue I have is that Twitter has since dropped this, the only
  other app I know of which uses this is the official Android
                          Contacts App.

To implement you’re own you’ll most likely want to use an open
                      source library.

      Fun, useful and a great idea, but not readily available.
So now what?
             Well now I’m going to go through *roughly* the development of this UI.
It’s something I’ve been working on recently and this presentation represents the rough process I
                                went through, from start to finish.
Before We Start
                         Every View should have at least the following states:

                                                 Normal
                                                 Focused
                                                 Pressed
                                                 Disabled

For those wondering “What is the focused state?” this is when a user uses the trackball to select a
view on the screen. Better to add it in from the start, it’s extra functionality, with little (if any) extra
                                               work.

 Making each of these states can be a little tedious, but if you make them all when you first make
                                  each View, it isn’t too bad :P

                              Boring bit said and done, lets get on with it.
Once there was a Button...
                                                                          Focused & Pressed
 The most simple and most widely used View is the Button.
                                                                            dark_std_button_pressed_bg
So how do we make one? Using the following XML with the
                    following images.
                                                                                 Pressed
<selector xmlns:android="http://schemas.android.com/apk/res/android">
       <item android:state_focused="true" android:state_pressed="true"      dark_std_button_pressed_bg
                                                                                                           These actually
             android:drawable="@drawable/dark_std_button_pressed_bg" />                                  look different on a
       <item android:state_focused="false" android:state_pressed="true"
             android:drawable="@drawable/dark_std_button_pressed_bg" />
                                                                                Focused                        device

       <item android:state_focused="true"
             android:drawable="@drawable/dark_std_button_focused_bg" />     dark_std_button_focused_bg
       <item android:drawable="@drawable/dark_std_button_bg" />
</selector>                                                                          Std.
                                                                               dark_std_button_bg
...Who met an EditText...
  Most apps will need to use an EditText at some point, the                   Focused & Pressed
reason I wanted to customise mine is to avoid Manufacturer’s
custom colour schemes (Orange, Green, Purple and then the                      std_edit_text_focused_pressed_bg
                      various ROM’s).                                                 Pressed
<selector xmlns:android="http://schemas.android.com/apk/res/android">
                                                                                   std_edit_text_pressed_bg
       <item android:state_focused="true" android:state_pressed="true"
           android:drawable="@drawable/std_edit_text_focused_pressed_bg" />           Focused
       <item android:state_focused="false" android:state_pressed="true"
           android:drawable="@drawable/std_edit_text_pressed_bg" />
       <item android:state_focused="true"                                          std_edit_text_focused_bg
           android:drawable="@drawable/std_edit_text_focused_bg" />
       <item android:drawable="@drawable/std_edit_text_bg" />
                                                                                           Std.
</selector>
                                                                                       std_edit_text_bg
...Who visited the CheckBox...
CheckBox is a little bit of extra work, having checked and non-checked
<selector xmlns:android="http://schemas.android.com/apk/res/android">              Focused & Pressed

      <item android:state_checked="true" android:state_focused="true"
           android:state_pressed="true"

      
     android:drawable="@drawable/                                     std_checkbox_unchecked     std_checkbox_checked
                std_checkbox_checked_focused_pressed" />
                         _focused_pressed          _focused_pressed

                                                                                              Pressed

      <item android:state_checked="false" android:state_focused="true"
           android:state_pressed="true"

      
     android:drawable="@drawable/
                std_checkbox_unchecked_focused_pressed" />

      <item android:state_checked="true" android:state_focused="true"        std_checkbox_unchecked     std_checkbox_checked

      
     android:drawable="@drawable/std_checkbox_checked_focused" />            _pressed                  _pressed


       <item android:state_checked="false" android:state_focused="true"
       
     android:drawable="@drawable/std_checkbox_unchecked_focused" />                   Focused

      <item android:state_checked="true" android:state_pressed="true"

      
     android:drawable="@drawable/std_checkbox_checked_pressed" />

      <item android:state_checked="false" android:state_pressed="true"       std_checkbox_unchecked     std_checkbox_checked

      
     android:drawable="@drawable/std_checkbox_unchecked_pressed" />           _focused                 _focused


       <item android:state_checked="true"
       
     android:drawable="@drawable/std_checkbox_checked" />                                 Std.

      <item android:state_checked="false"

      
     android:drawable="@drawable/std_checkbox_unchecked" />
</selector>                                                                   std_checkbox_unchecked     std_checkbox_checked
...But the CheckBox was Fussy...
         There is one thing you may struggle with when customising your CheckBox.

             The View has a Background & a Button property, the difference?
The Background defines where content can go (i.e. the text you can set as the CheckBox label)

                              For my app I have the following:


              Button                  Background                               label here




                                                           =
Where do I put all this stuff?
With a new Android project you’ll get a standard file structure. This is what each folder means :)
                                                                  All your images (i.e. for buttons, checkbox etc.) should have a copy of each
+src                                                                graphic in drawable-hdpi, -mdpi, -ldpi. (Each copy is for different screen
  - All your awesome source code                                         resolutions (1.5, 1, 0.75 x the graphic size for hdpi, mdpi, ldpi).
+res                                                            The point of this is the displayed image should be roughly the same physical size.
  - anim [Animation XML files]
  - drawable                                                    Then any xml (the stuff on the previos slides) should be placed in the drawable
     -Put all your XML drawables here (Button, Checkbox etc.)                                       folder.
  - drawable-hdpi
     - 1.5 * MDPI graphic size (PNG, JPG, Nine-Patch PNG)        In the XML you’ll notice references to @drawable/some_img_name this tells
  -drawable-mdpi                                                the Android platform to find a drawable with the name some_img_name in one
     - 1 * MDPI graphic size (PNG, JPG, Nine-Patch PNG)         of the drawable folders. Which folder is determined by the system, based on the
  -drawable-ldpi                                                                         screen resolution of the device.
     - 0.75 * MDPI graphic size (PNG, JPG, Nine-Patch PNG)
  -layout                                                       Roman Nurik has said that all XML should go into the drawable folder, I’m sure I
  -layout-land                                                    have seen gradients appear scaled / manipulated if I put it inside the drawable
  -values                                                       folder rather than individually in each folder. So do as Roman says, he’s far wiser
  -values-land                                                            than I, but bare in mind it could be the cause of some issues.
+assets
+bin                                                                                  I Can Haz Screen Sizes? *For most devices
+gen                                                                                           HDPI - 480 x 800
AndroidManifest.xml                                                                            MDPI - 320 x 480
                                                                                               LDPI - 240 x 320
Wow - Can I Code Now?
      One last bit of XML based fun, but this step will save you a lot of time and frustration.

  At the moment to apply your background to a Button, you have to set the background of the
button in the layout file, you then have to do that for EACH of your buttons. Wouldn’t it be cool if
   you could tell Android to use the same background for all your buttons, but only do it once?

                                   In comes Themes and Styles.
                       We’ll start with Styles and then move on to themes.
Ok, No Code - Styles huh...
           Lets carry on with our Button, we want a style we can apply to our button.

                                           So what exactly is a style?
                    <style name="admobBtnStyle" parent="android:style/Widget.Button">
                    
      <item name="android:background">@drawable/std_btn_stateful</item>
                    
      <item name="android:textColor">@color/btn_text</item>
                    
      <item name="android:paddingLeft">@dimen/btn_padding_left_right</item>
                    
      <item name="android:paddingRight">@dimen/btn_padding_left_right</item>
                    
      <item name="android:paddingTop">@dimen/btn_padding_top_bottom</item>
                    
      <item name="android:paddingBottom">@dimen/btn_padding_top_bottom</item>
                    
      <item name="android:textSize">@dimen/btn_text_size</item>
                    
      <item name="android:minHeight">@dimen/btn_min_height</item>
                    
      <item name="android:minWidth">@dimen/btn_min_width</item>
                    </style>
 Imagine what you might want to set on a button, the background, textColor, textSize, padding . . .
 you get the picture. Do it in a style, then in a layout you can apply the “style” to a button, rather
than each field individually. This means, one change here applies to all your buttons using this style
                         AND the layout is free to override these values.

  I know what you’re thinking - you still need to apply the style to ALL your buttons . . well . . .
Themes FTW
... if you apply the style to a Button widget in a Theme, the system automatically applies the style
                                     to all your Buttons - Simples.

                   <style name="AdmobTheme" parent="android:style/Theme.Light.NoTitleBar">
                      <item name="android:windowBackground">@color/activity_bg</item>
                      <item name="android:editTextStyle">@style/admobEditText</item>
                      <item name="android:buttonStyle">@style/admobBtnStyle</item>
                      <item name="android:checkboxStyle">@style/admobCheckboxStyle</item>
                   </style>

                               So why have I made you do all this?

In the long run you’ll thank me, there is nothing more soul destroying than going through all your
              code, altering Buttons to have padding of 2 pixels to the left and right.

  For reference, the Styles for the CheckBox & EditText are on the next two slides (Useful for
                             parent styles, the rest you can work out).
CheckBox Style
                                 Yup.


<style name="admobCheckboxStyle" parent="android:style/Widget.CompoundButton.CheckBox">

      <item name="android:button">@drawable/std_checkbox_stateful</item>

      <item name="android:background">@drawable/std_checkbox_bg</item>
</style>
EditText Style
                              Double Yup.


<style name="admobEditText" parent="android:Widget.EditText">

      <item name="android:background">@drawable/std_edit_text_stateful</item>
</style>
Last Style Trick - Then Pictures
                             The last little thing I want to make you aware of.

Say you have two buttons, one is light, one is dark, you want them to share the same parameters apart from
  the background drawable. Well you can achieve this by having one style being the parent, and the other
                                            extending the parent.

 The standard method of doing this is to create a style with same name plus an extension and setting the
                                              parent attrib:
                        <style name="admobBtnStyle" parent="android:style/Widget.Button">
                        
      <item name="android:background">@drawable/std_btn_stateful</item>
                        
      <item name="android:textColor">@color/btn_text</item>
                        
      <item name="android:paddingLeft">@dimen/btn_padding_left_right</item>
                        
      <item name="android:paddingRight">@dimen/btn_padding_left_right</item>
                        
      <item name="android:paddingTop">@dimen/btn_padding_top_bottom</item>
                        
      <item name="android:paddingBottom">@dimen/btn_padding_top_bottom</item>
                        
      <item name="android:textSize">@dimen/btn_text_size</item>
                        
      <item name="android:minHeight">@dimen/btn_min_height</item>
                        
      <item name="android:minWidth">@dimen/btn_min_width</item>
                        </style>
                        <style name="admobBtnStyle.Dark" parent="style/admobBtnStyle">
                        
      <item name="android:background">@drawable/dark_std_btn_stateful</item>
                        </style>
The Action Bar - Code Code Code
 The logo shoud take the user to the dashboard - when this
 happens you’ll want the other Activities in your app to finish
          so be sure to start your Activity with the
  FLAG_ACTIVITY_CLEAR_TOP flag (See intent.setFlag())

             Modal Dialogs - Pah - Utter Rubbish.




Instead, hit my refresh button and it changes to a Progress Bar.

 Custom Views aren’t too bad, give them a shot if nothing does
      what you want. [But use Adapters where you can]
ListViews - Mix it Up a Little
                                       ListView 101

1. Personally, I’m not a fan of ListActivity
2. Personally, I’m not a fan of helper Adapters
3. Use convertView in the getView() method or a kitten will
   die for every view you fail to recycle

                                                 Hints:
                                            cacheColorHint
       Set this to an invisible color to stop the fading edges from turning black - #00000000

                                         dividerDrawable
               You can change the dividers so they are colored or just a bit different

                                           background
The drawable set to the background will react to different states (pressed, focused, focused pressed)

                                           listSelector
               Ever wanted to stop the orange highlighting? listSelector = #00000000
Landscape is Easy in Android
One thing many developers turn off is landscape rotation. I understand that it’s a little tricky when
      you’re Activity dies and starts again, but handle it and you can get some cool effects.




                                      Check out Mark Murphy’s posts on the matter:
                           www.androidguys.com/2008/10/14/rotational-forceson-your-android-app/
Dialogs - Oh God the Dialog
  You’re not using modal Dialog’s, good, but you do still kinda want to use them, but they kinda
                                    don’t really suite your app.

 For me this is a step in the right direction (but not complete), the background image is just a
shape (shape is a drawable defined in XML). This is then used in a Theme which is applied in the
                           AndroidManifest.xml to a reusable Activity.
Background
<?xml version="1.0" encoding="utf-8"?>
<shape
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle">

      <corners android:radius="@dimen/dialog_rounded_corners" />
     <solid android:color="@color/dialog_container_bg_color" />
     <stroke android:width="@dimen/dialog_stroke_width"
     android:color="@color/dialog_stroke_color" />
</shape>

Theme
<style name="AdmobDialogTheme" parent="android:style/Theme.Dialog">
   <item name="android:windowBackground">@drawable/generic_dialog_bg</item>
   <item name="android:windowFrame">@null</item>
   <item name="android:windowContentOverlay">@null</item>
   <item name="android:textViewStyle">@style/admobTextView</item>
   <item name="android:windowNoTitle">true</item>
   <item name="android:buttonStyle">@style/admobBtnStyle</item>
</style>
Last Tid Bit - Cos. . .
                                         ...it took me ages to find this out!

     How to switch the ProgressBar between dark and light (depending on your parent theme).



<ProgressBar
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"></ProgressBar>

<ProgressBar
  android:layout_width="@dimen/action_bar_btn_size"
  android:layout_height="@dimen/action_bar_btn_size"
  style="?android:attr/progressBarStyleInverse"></ProgressBar>
.Fin

Weitere ähnliche Inhalte

Was ist angesagt?

Creating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchCreating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchRuss Weakley
 
STYLISH FLOOR
STYLISH FLOORSTYLISH FLOOR
STYLISH FLOORABU HASAN
 
The touch events - WebExpo
The touch events - WebExpoThe touch events - WebExpo
The touch events - WebExpoPeter-Paul Koch
 
3DXplorer Users manual
3DXplorer Users manual3DXplorer Users manual
3DXplorer Users manualMohamed Omar
 
A comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter componentA comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter componentKaty Slemon
 

Was ist angesagt? (8)

Advance JFACE
Advance JFACEAdvance JFACE
Advance JFACE
 
Creating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchCreating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off Switch
 
STYLISH FLOOR
STYLISH FLOORSTYLISH FLOOR
STYLISH FLOOR
 
Popup view on Mortar
Popup view on MortarPopup view on Mortar
Popup view on Mortar
 
Work flow
Work flowWork flow
Work flow
 
The touch events - WebExpo
The touch events - WebExpoThe touch events - WebExpo
The touch events - WebExpo
 
3DXplorer Users manual
3DXplorer Users manual3DXplorer Users manual
3DXplorer Users manual
 
A comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter componentA comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter component
 

Andere mochten auch

Mobile in a Nutshell
Mobile in a NutshellMobile in a Nutshell
Mobile in a NutshellGauntFace
 
Android Fragment-Awesome
Android Fragment-AwesomeAndroid Fragment-Awesome
Android Fragment-AwesomeGauntFace
 
Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Davide Cerbo
 
Advance Android application development workshop day 1
Advance Android application development workshop day 1Advance Android application development workshop day 1
Advance Android application development workshop day 1cresco
 
Advance Android Programming - learning beyond basics
Advance Android Programming - learning beyond basicsAdvance Android Programming - learning beyond basics
Advance Android Programming - learning beyond basicsayman diab
 
Android Workshop 2013
Android Workshop 2013Android Workshop 2013
Android Workshop 2013Junda Ong
 
Memory problems in android programming
Memory problems in android programmingMemory problems in android programming
Memory problems in android programmingAiTi Education
 
Software proposal on android
Software proposal on androidSoftware proposal on android
Software proposal on androidKamrul Chowdhury
 
Asynchronous Programming in Android
Asynchronous Programming in AndroidAsynchronous Programming in Android
Asynchronous Programming in AndroidJohn Pendexter
 
Advance Android application development workshop day 3
Advance Android application development workshop day 3Advance Android application development workshop day 3
Advance Android application development workshop day 3cresco
 
Tips and tricks to attack memory problem in android programming
Tips and tricks to attack memory problem in android programmingTips and tricks to attack memory problem in android programming
Tips and tricks to attack memory problem in android programmingZalo_app
 
Stream upload and asynchronous job processing in large scale systems
Stream upload and asynchronous job processing  in large scale systemsStream upload and asynchronous job processing  in large scale systems
Stream upload and asynchronous job processing in large scale systemsZalo_app
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application DevelopmentRamesh Prasad
 
Android Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App DevelopersAndroid Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App DevelopersReto Meier
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on AndroidTomáš Kypta
 
Android app development - Java Programming for Android
Android app development - Java Programming for AndroidAndroid app development - Java Programming for Android
Android app development - Java Programming for AndroidOUM SAOKOSAL
 

Andere mochten auch (20)

Mobile in a Nutshell
Mobile in a NutshellMobile in a Nutshell
Mobile in a Nutshell
 
Android Fragment-Awesome
Android Fragment-AwesomeAndroid Fragment-Awesome
Android Fragment-Awesome
 
Advance Android Layout Walkthrough
Advance Android Layout WalkthroughAdvance Android Layout Walkthrough
Advance Android Layout Walkthrough
 
Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Non Conventional Android Programming (English)
Non Conventional Android Programming (English)
 
Advance Android application development workshop day 1
Advance Android application development workshop day 1Advance Android application development workshop day 1
Advance Android application development workshop day 1
 
Advance Android Programming - learning beyond basics
Advance Android Programming - learning beyond basicsAdvance Android Programming - learning beyond basics
Advance Android Programming - learning beyond basics
 
Android Workshop 2013
Android Workshop 2013Android Workshop 2013
Android Workshop 2013
 
Memory problems in android programming
Memory problems in android programmingMemory problems in android programming
Memory problems in android programming
 
Software proposal on android
Software proposal on androidSoftware proposal on android
Software proposal on android
 
Asynchronous Programming in Android
Asynchronous Programming in AndroidAsynchronous Programming in Android
Asynchronous Programming in Android
 
Advance Android application development workshop day 3
Advance Android application development workshop day 3Advance Android application development workshop day 3
Advance Android application development workshop day 3
 
Web Development Fundamentals
Web Development FundamentalsWeb Development Fundamentals
Web Development Fundamentals
 
Tips and tricks to attack memory problem in android programming
Tips and tricks to attack memory problem in android programmingTips and tricks to attack memory problem in android programming
Tips and tricks to attack memory problem in android programming
 
Stream upload and asynchronous job processing in large scale systems
Stream upload and asynchronous job processing  in large scale systemsStream upload and asynchronous job processing  in large scale systems
Stream upload and asynchronous job processing in large scale systems
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
Coding defines reality
Coding defines realityCoding defines reality
Coding defines reality
 
Android Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App DevelopersAndroid Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App Developers
 
Android Programming
Android ProgrammingAndroid Programming
Android Programming
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
Android app development - Java Programming for Android
Android app development - Java Programming for AndroidAndroid app development - Java Programming for Android
Android app development - Java Programming for Android
 

Ähnlich wie Android UI Reference

Lecture #1 Creating your first android project
Lecture #1  Creating your first android projectLecture #1  Creating your first android project
Lecture #1 Creating your first android projectVitali Pekelis
 
01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgetsSiva Kumar reddy Vasipally
 
Getting Started With Material Design
Getting Started With Material DesignGetting Started With Material Design
Getting Started With Material DesignYasin Yildirim
 
Android howto hellowidget
Android howto hellowidgetAndroid howto hellowidget
Android howto hellowidgetHiron Das
 
Lecture #3 activities and intents
Lecture #3  activities and intentsLecture #3  activities and intents
Lecture #3 activities and intentsVitali Pekelis
 
Android N Highligts
Android N HighligtsAndroid N Highligts
Android N HighligtsSercan Yusuf
 
21 android2 updated
21 android2 updated21 android2 updated
21 android2 updatedGhanaGTUG
 
Material design basics
Material design basicsMaterial design basics
Material design basicsJorge Barroso
 
Android Kotlin Weather App Project.pdf
Android Kotlin Weather App Project.pdfAndroid Kotlin Weather App Project.pdf
Android Kotlin Weather App Project.pdfSudhanshiBakre1
 
Multi Window in Android N
Multi Window in Android NMulti Window in Android N
Multi Window in Android NTaeho Kim
 
9 Step Guide to Create Ripple View Effect in Android
9 Step Guide to Create Ripple View Effect in Android9 Step Guide to Create Ripple View Effect in Android
9 Step Guide to Create Ripple View Effect in AndroidNine Hertz
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recieversUtkarsh Mankad
 

Ähnlich wie Android UI Reference (20)

Lecture #1 Creating your first android project
Lecture #1  Creating your first android projectLecture #1  Creating your first android project
Lecture #1 Creating your first android project
 
Android Button
Android ButtonAndroid Button
Android Button
 
01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgets
 
Getting Started With Material Design
Getting Started With Material DesignGetting Started With Material Design
Getting Started With Material Design
 
Android how to hellowidget
Android how to hellowidgetAndroid how to hellowidget
Android how to hellowidget
 
Android howto hellowidget
Android howto hellowidgetAndroid howto hellowidget
Android howto hellowidget
 
Lecture #3 activities and intents
Lecture #3  activities and intentsLecture #3  activities and intents
Lecture #3 activities and intents
 
Android N Highligts
Android N HighligtsAndroid N Highligts
Android N Highligts
 
Ap quiz app
Ap quiz appAp quiz app
Ap quiz app
 
Android
AndroidAndroid
Android
 
Android app development guide for freshers by ace web academy
Android app development guide for freshers  by ace web academyAndroid app development guide for freshers  by ace web academy
Android app development guide for freshers by ace web academy
 
21 android2 updated
21 android2 updated21 android2 updated
21 android2 updated
 
Material design basics
Material design basicsMaterial design basics
Material design basics
 
Android Kotlin Weather App Project.pdf
Android Kotlin Weather App Project.pdfAndroid Kotlin Weather App Project.pdf
Android Kotlin Weather App Project.pdf
 
Multi Window in Android N
Multi Window in Android NMulti Window in Android N
Multi Window in Android N
 
Getting started with android studio
Getting started with android studioGetting started with android studio
Getting started with android studio
 
9 Step Guide to Create Ripple View Effect in Android
9 Step Guide to Create Ripple View Effect in Android9 Step Guide to Create Ripple View Effect in Android
9 Step Guide to Create Ripple View Effect in Android
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
How to create android push notifications with custom view
How to create android push notifications with custom viewHow to create android push notifications with custom view
How to create android push notifications with custom view
 
Hierarchy viewer
Hierarchy viewerHierarchy viewer
Hierarchy viewer
 

Kürzlich hochgeladen

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 

Kürzlich hochgeladen (20)

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 

Android UI Reference

  • 1. Android UI Reference By Matthew Gaunt
  • 2. Who? What? Why? Hi, I’m Matt Gaunt (@gauntface) I’ve been developing on Android, on and off, for the past 2 years (starting from the 0.9 SDK). The reason I’ve put this document together is to help others with things I struggled with when I first started out, to help others learn new things with Android UI and to inform people about some of the new Android design patterns. This presentation will be suitable for learning, for reference and also great for people just wondering what Android UI is all about. If you spot something wrong or disagree, then let me know :) E-mail Address: matt@gauntface.co.uk
  • 3. What Google Want - Dashboard Lets start off with what Google want developers to do. The Dashboard This is a nice simple, clean and frankly easy to follow design pattern. Have a panel with 4 - 6 of your app’s main functions. Example Apps: Twitter, Facebook, Google Places Note: You don’t have to open your app on this screen
  • 4. What Google Want - Action Bar The Action Bar One thing many dev’s do, is needlessy fill the screen, removing the notification bar from the UI. The only reason I can think of why someone might do this, is to get rid of the, not so pretty, title bar. Instead Google are recommending the Action Bar. The logo on the right should link to the dashboard and the left side should have buttons relevant to that activity - Perfect :) Examples - Facebook, Twitter and many more
  • 5. What Google Want - Quick Action The Quick Action This one I have some reservations about. It’s a very kool and fun way to give extra functionality in an intuitive way, especially for specific elements on screen (i.e. a list item or for displaying extra info). The issue I have is that Twitter has since dropped this, the only other app I know of which uses this is the official Android Contacts App. To implement you’re own you’ll most likely want to use an open source library. Fun, useful and a great idea, but not readily available.
  • 6. So now what? Well now I’m going to go through *roughly* the development of this UI. It’s something I’ve been working on recently and this presentation represents the rough process I went through, from start to finish.
  • 7. Before We Start Every View should have at least the following states: Normal Focused Pressed Disabled For those wondering “What is the focused state?” this is when a user uses the trackball to select a view on the screen. Better to add it in from the start, it’s extra functionality, with little (if any) extra work. Making each of these states can be a little tedious, but if you make them all when you first make each View, it isn’t too bad :P Boring bit said and done, lets get on with it.
  • 8. Once there was a Button... Focused & Pressed The most simple and most widely used View is the Button. dark_std_button_pressed_bg So how do we make one? Using the following XML with the following images. Pressed <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:state_pressed="true" dark_std_button_pressed_bg These actually android:drawable="@drawable/dark_std_button_pressed_bg" /> look different on a <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/dark_std_button_pressed_bg" /> Focused device <item android:state_focused="true" android:drawable="@drawable/dark_std_button_focused_bg" /> dark_std_button_focused_bg <item android:drawable="@drawable/dark_std_button_bg" /> </selector> Std. dark_std_button_bg
  • 9. ...Who met an EditText... Most apps will need to use an EditText at some point, the Focused & Pressed reason I wanted to customise mine is to avoid Manufacturer’s custom colour schemes (Orange, Green, Purple and then the std_edit_text_focused_pressed_bg various ROM’s). Pressed <selector xmlns:android="http://schemas.android.com/apk/res/android"> std_edit_text_pressed_bg <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/std_edit_text_focused_pressed_bg" /> Focused <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/std_edit_text_pressed_bg" /> <item android:state_focused="true" std_edit_text_focused_bg android:drawable="@drawable/std_edit_text_focused_bg" /> <item android:drawable="@drawable/std_edit_text_bg" /> Std. </selector> std_edit_text_bg
  • 10. ...Who visited the CheckBox... CheckBox is a little bit of extra work, having checked and non-checked <selector xmlns:android="http://schemas.android.com/apk/res/android"> Focused & Pressed <item android:state_checked="true" android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/ std_checkbox_unchecked std_checkbox_checked std_checkbox_checked_focused_pressed" /> _focused_pressed _focused_pressed Pressed <item android:state_checked="false" android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/ std_checkbox_unchecked_focused_pressed" /> <item android:state_checked="true" android:state_focused="true" std_checkbox_unchecked std_checkbox_checked android:drawable="@drawable/std_checkbox_checked_focused" /> _pressed _pressed <item android:state_checked="false" android:state_focused="true" android:drawable="@drawable/std_checkbox_unchecked_focused" /> Focused <item android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/std_checkbox_checked_pressed" /> <item android:state_checked="false" android:state_pressed="true" std_checkbox_unchecked std_checkbox_checked android:drawable="@drawable/std_checkbox_unchecked_pressed" /> _focused _focused <item android:state_checked="true" android:drawable="@drawable/std_checkbox_checked" /> Std. <item android:state_checked="false" android:drawable="@drawable/std_checkbox_unchecked" /> </selector> std_checkbox_unchecked std_checkbox_checked
  • 11. ...But the CheckBox was Fussy... There is one thing you may struggle with when customising your CheckBox. The View has a Background & a Button property, the difference? The Background defines where content can go (i.e. the text you can set as the CheckBox label) For my app I have the following: Button Background label here =
  • 12. Where do I put all this stuff? With a new Android project you’ll get a standard file structure. This is what each folder means :) All your images (i.e. for buttons, checkbox etc.) should have a copy of each +src graphic in drawable-hdpi, -mdpi, -ldpi. (Each copy is for different screen - All your awesome source code resolutions (1.5, 1, 0.75 x the graphic size for hdpi, mdpi, ldpi). +res The point of this is the displayed image should be roughly the same physical size. - anim [Animation XML files] - drawable Then any xml (the stuff on the previos slides) should be placed in the drawable -Put all your XML drawables here (Button, Checkbox etc.) folder. - drawable-hdpi - 1.5 * MDPI graphic size (PNG, JPG, Nine-Patch PNG) In the XML you’ll notice references to @drawable/some_img_name this tells -drawable-mdpi the Android platform to find a drawable with the name some_img_name in one - 1 * MDPI graphic size (PNG, JPG, Nine-Patch PNG) of the drawable folders. Which folder is determined by the system, based on the -drawable-ldpi screen resolution of the device. - 0.75 * MDPI graphic size (PNG, JPG, Nine-Patch PNG) -layout Roman Nurik has said that all XML should go into the drawable folder, I’m sure I -layout-land have seen gradients appear scaled / manipulated if I put it inside the drawable -values folder rather than individually in each folder. So do as Roman says, he’s far wiser -values-land than I, but bare in mind it could be the cause of some issues. +assets +bin I Can Haz Screen Sizes? *For most devices +gen HDPI - 480 x 800 AndroidManifest.xml MDPI - 320 x 480 LDPI - 240 x 320
  • 13. Wow - Can I Code Now? One last bit of XML based fun, but this step will save you a lot of time and frustration. At the moment to apply your background to a Button, you have to set the background of the button in the layout file, you then have to do that for EACH of your buttons. Wouldn’t it be cool if you could tell Android to use the same background for all your buttons, but only do it once? In comes Themes and Styles. We’ll start with Styles and then move on to themes.
  • 14. Ok, No Code - Styles huh... Lets carry on with our Button, we want a style we can apply to our button. So what exactly is a style? <style name="admobBtnStyle" parent="android:style/Widget.Button"> <item name="android:background">@drawable/std_btn_stateful</item> <item name="android:textColor">@color/btn_text</item> <item name="android:paddingLeft">@dimen/btn_padding_left_right</item> <item name="android:paddingRight">@dimen/btn_padding_left_right</item> <item name="android:paddingTop">@dimen/btn_padding_top_bottom</item> <item name="android:paddingBottom">@dimen/btn_padding_top_bottom</item> <item name="android:textSize">@dimen/btn_text_size</item> <item name="android:minHeight">@dimen/btn_min_height</item> <item name="android:minWidth">@dimen/btn_min_width</item> </style> Imagine what you might want to set on a button, the background, textColor, textSize, padding . . . you get the picture. Do it in a style, then in a layout you can apply the “style” to a button, rather than each field individually. This means, one change here applies to all your buttons using this style AND the layout is free to override these values. I know what you’re thinking - you still need to apply the style to ALL your buttons . . well . . .
  • 15. Themes FTW ... if you apply the style to a Button widget in a Theme, the system automatically applies the style to all your Buttons - Simples. <style name="AdmobTheme" parent="android:style/Theme.Light.NoTitleBar"> <item name="android:windowBackground">@color/activity_bg</item> <item name="android:editTextStyle">@style/admobEditText</item> <item name="android:buttonStyle">@style/admobBtnStyle</item> <item name="android:checkboxStyle">@style/admobCheckboxStyle</item> </style> So why have I made you do all this? In the long run you’ll thank me, there is nothing more soul destroying than going through all your code, altering Buttons to have padding of 2 pixels to the left and right. For reference, the Styles for the CheckBox & EditText are on the next two slides (Useful for parent styles, the rest you can work out).
  • 16. CheckBox Style Yup. <style name="admobCheckboxStyle" parent="android:style/Widget.CompoundButton.CheckBox"> <item name="android:button">@drawable/std_checkbox_stateful</item> <item name="android:background">@drawable/std_checkbox_bg</item> </style>
  • 17. EditText Style Double Yup. <style name="admobEditText" parent="android:Widget.EditText"> <item name="android:background">@drawable/std_edit_text_stateful</item> </style>
  • 18. Last Style Trick - Then Pictures The last little thing I want to make you aware of. Say you have two buttons, one is light, one is dark, you want them to share the same parameters apart from the background drawable. Well you can achieve this by having one style being the parent, and the other extending the parent. The standard method of doing this is to create a style with same name plus an extension and setting the parent attrib: <style name="admobBtnStyle" parent="android:style/Widget.Button"> <item name="android:background">@drawable/std_btn_stateful</item> <item name="android:textColor">@color/btn_text</item> <item name="android:paddingLeft">@dimen/btn_padding_left_right</item> <item name="android:paddingRight">@dimen/btn_padding_left_right</item> <item name="android:paddingTop">@dimen/btn_padding_top_bottom</item> <item name="android:paddingBottom">@dimen/btn_padding_top_bottom</item> <item name="android:textSize">@dimen/btn_text_size</item> <item name="android:minHeight">@dimen/btn_min_height</item> <item name="android:minWidth">@dimen/btn_min_width</item> </style> <style name="admobBtnStyle.Dark" parent="style/admobBtnStyle"> <item name="android:background">@drawable/dark_std_btn_stateful</item> </style>
  • 19. The Action Bar - Code Code Code The logo shoud take the user to the dashboard - when this happens you’ll want the other Activities in your app to finish so be sure to start your Activity with the FLAG_ACTIVITY_CLEAR_TOP flag (See intent.setFlag()) Modal Dialogs - Pah - Utter Rubbish. Instead, hit my refresh button and it changes to a Progress Bar. Custom Views aren’t too bad, give them a shot if nothing does what you want. [But use Adapters where you can]
  • 20. ListViews - Mix it Up a Little ListView 101 1. Personally, I’m not a fan of ListActivity 2. Personally, I’m not a fan of helper Adapters 3. Use convertView in the getView() method or a kitten will die for every view you fail to recycle Hints: cacheColorHint Set this to an invisible color to stop the fading edges from turning black - #00000000 dividerDrawable You can change the dividers so they are colored or just a bit different background The drawable set to the background will react to different states (pressed, focused, focused pressed) listSelector Ever wanted to stop the orange highlighting? listSelector = #00000000
  • 21. Landscape is Easy in Android One thing many developers turn off is landscape rotation. I understand that it’s a little tricky when you’re Activity dies and starts again, but handle it and you can get some cool effects. Check out Mark Murphy’s posts on the matter: www.androidguys.com/2008/10/14/rotational-forceson-your-android-app/
  • 22. Dialogs - Oh God the Dialog You’re not using modal Dialog’s, good, but you do still kinda want to use them, but they kinda don’t really suite your app. For me this is a step in the right direction (but not complete), the background image is just a shape (shape is a drawable defined in XML). This is then used in a Theme which is applied in the AndroidManifest.xml to a reusable Activity. Background <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="@dimen/dialog_rounded_corners" /> <solid android:color="@color/dialog_container_bg_color" /> <stroke android:width="@dimen/dialog_stroke_width" android:color="@color/dialog_stroke_color" /> </shape> Theme <style name="AdmobDialogTheme" parent="android:style/Theme.Dialog"> <item name="android:windowBackground">@drawable/generic_dialog_bg</item> <item name="android:windowFrame">@null</item> <item name="android:windowContentOverlay">@null</item> <item name="android:textViewStyle">@style/admobTextView</item> <item name="android:windowNoTitle">true</item> <item name="android:buttonStyle">@style/admobBtnStyle</item> </style>
  • 23. Last Tid Bit - Cos. . . ...it took me ages to find this out! How to switch the ProgressBar between dark and light (depending on your parent theme). <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content"></ProgressBar> <ProgressBar android:layout_width="@dimen/action_bar_btn_size" android:layout_height="@dimen/action_bar_btn_size" style="?android:attr/progressBarStyleInverse"></ProgressBar>
  • 24. .Fin