Implement action bar with style in android app development

5
Implement Action-bar With Style in Android App Development "Android Application Development Company India" www.letsnurture.com

description

Implement action bar with style in android app development

Transcript of Implement action bar with style in android app development

Page 1: Implement action bar with style in android app development

Implement Action-bar With Style in Android App

Development

"Android Application Development Company India" www.letsnurture.com

Page 2: Implement action bar with style in android app development

Actionbar Support Lib

Why to use Support Lib ?

-There are several libraries designed to be used with Android 2.1 (API level 7) and higher. These libraries provide specific feature sets and can be included in your application independently from each other.

To get started with Support Library v7 you will need to simply add the Support Library v7 AppCompat from the Component Store into your Android App.

Make sure that you've installed already the following libraries Android Support Library, Android Support Repository and Google Repository by checking in the Extra folder by openning the Android SDK Manager in eclipse.

Add android-support-v7-appcompat lib project to your Workspace.

1.In the Project Explorer, right-click and import and click on Exitsing project in to Work space 2. navigate to <sdk>/extras/android/support/v7/appcompat/3. Finish.

Now follow below step.

Add the library to your application project:1.In the Project Explorer, right-click your project and select Properties.2.In the Library pane, click Add.3.Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat.

"Android Application Development Company India" www.letsnurture.com

Page 3: Implement action bar with style in android app development

4.In the properties window, click OK.

Now follow bellow steps to change in project.

1.Extend ActionBarActivity “Not Activity”2.Add android:theme=”@style/Theme.AppCompat.Light” to the activity that will show the action bar3.Use Custom Namespace for showAsAction Attribute

Styling your Action Bar in AppCompat is a little bit different as now there are unified themes including:

Holo: @style/Theme.AppCompat

Holo Light: @style/Theme.AppCompat.Light

Holo Light with Dark Action Bar:

@style/Theme.AppCompat.Light.DarkActionBar

Adding Actions:Android Action Bar items are defined in your Menu xml files. If you have created menus before you can simply update your xml files as there are a few key differences. First, is that you will want to update your icons so they are the correct size for the Action Bar. You can use Google’s Android Asset Studio to generate these new icons. Second, is that there are new specific attributes on the menu items that define Action Bar specific functionality such as “showAsAction”, which is used to determine which items are always in the Action Bar or if they are in the over flow. Here is an example of setting this:

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" >

<item

android:id="@+id/play"

android:icon="@android:drawable/ic_menu_upload"

android:title = "Play"

app:showAsAction="ifRoom">

"Android Application Development Company India" www.letsnurture.com

Page 4: Implement action bar with style in android app development

</item>

<item

android:id="@+id/stop"

android:icon="@android:drawable/ic_btn_speak_now"

android:title = "Stop"

app:actionProviderClass="android.support.v7.widget.ShareActionProvider"

app:showAsAction="ifRoom"/>

</menu>

The most important part here is that I added a custom “xmlns” definition of

xmlns:app=”http://schemas.android.com/apk/res-auto” which is used by

Android to find where the property is located when we use it in

“app:showAsAction”.

Link to Example

"Android Application Development Company India" www.letsnurture.com