Skip to content

Commit

Permalink
Updated example to demonstrate custom styling of tabs.
Browse files Browse the repository at this point in the history
  • Loading branch information
johannilsson committed May 28, 2011
1 parent a73a9e6 commit d007033
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 3 deletions.
10 changes: 7 additions & 3 deletions actionbarexample/AndroidManifest.xml
Expand Up @@ -3,18 +3,22 @@
package="com.markupartist.android.actionbar.example"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/Theme.ActionBar"
>
<activity android:name=".HomeActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".OtherActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
android:theme="@style/OtherTheme"
>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="10"/>
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions actionbarexample/res/drawable/tab_custom_indicator.xml
@@ -0,0 +1,42 @@
<!--
Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- selected tabs -->
<item android:drawable="@drawable/tab_custom_selected_pressed"
android:state_selected="true"
android:state_pressed="true" />
<item android:drawable="@drawable/tab_custom_selected_focused"
android:state_selected="true"
android:state_pressed="false"
android:state_focused="true" />
<item android:drawable="@drawable/tab_custom_selected"
android:state_selected="true"
android:state_focused="false"
android:state_pressed="false" />

<!-- unselected tabs -->
<item android:drawable="@drawable/tab_custom_unselected_pressed"
android:state_selected="false"
android:state_pressed="true" />
<item android:drawable="@drawable/tab_custom_unselected_focused"
android:state_selected="false"
android:state_pressed="false"
android:state_focused="true" />
<item android:drawable="@drawable/tab_custom_unselected"
android:state_selected="false"
android:state_focused="false"
android:state_pressed="false" />
</selector>
25 changes: 25 additions & 0 deletions actionbarexample/res/values/styles.xml
Expand Up @@ -22,4 +22,29 @@
<style name="ActionBarProgressBar" parent="@android:style/Widget.ProgressBar.Small.Inverse">
</style>
-->

<!-- Demonstrates how we can style the action bar differently for another
activity. Drawables for the tabs used in this examples has been stolen
from the iosched app <http://code.google.com/p/iosched>. -->
<style name="OtherTheme" parent="@style/Theme.ActionBar.Light">
<item name="actionBarTabBarStyle">@style/FancyTabBar</item>
<item name="actionBarTabViewStyle">@style/FancyTabView</item>
<item name="actionBarTabTextStyle">@style/FancyTabText</item>
</style>

<style name="FancyTabBar" parent="ActionBar_TabBar">
<item name="android:background">@drawable/tab_custom_off_background</item>
<item name="android:paddingTop">5dip</item>
<item name="android:layout_height">38dp</item>
</style>
<style name="FancyTabView" parent="ActionBar_TabView">
<item name="android:background">@drawable/tab_custom_indicator</item>
<item name="android:layout_height">38dp</item>
<item name="android:layout_marginLeft">2dip</item>
<item name="android:layout_marginRight">2dip</item>
</style>
<style name="FancyTabText" parent="ActionBar_TabText">
<item name="android:textColor">?android:attr/textColorPrimary</item>
<item name="android:textSize">14sp</item>
</style>
</resources>
Expand Up @@ -30,6 +30,7 @@ public void onCreate(Bundle savedInstanceState) {
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.addTab(actionBar.newTab().setText("Tab 1").setTabListener(this));
actionBar.addTab(actionBar.newTab().setText("Tab 2").setTabListener(this));
actionBar.addTab(actionBar.newTab().setText("Tab 3").setTabListener(this));

actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
Expand Down

0 comments on commit d007033

Please sign in to comment.