Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
styling v21 compatibility android actionbar
package com.doodkin.example;
import android.support.v7.app.ActionBarActivity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//add icon of application to actionbar (up button):
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_launcher);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_main);
}
}
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light" >
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
<item name="android:windowNoTitle">true</item>
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:textColorPrimary">@color/text_primary</item>
<item name="android:textColor">@color/text_secondary</item>
<!-- <item name="android:navigationBarColor">@color/primary_dark</item> // v21-->
<item name="actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
</style>
<!--set image to settings menu button-->
<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">@drawable/small_menu_button</item>
<item name="android:scaleType">centerInside</item>
<item name="android:paddingTop">14dp</item>
<item name="android:paddingBottom">14dp</item>
</style>
</resources>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.doodkin.example.MainActivity"
android:icon="@drawable/ic_launcher"
>
<!--
add icons (buttons) to actionbar:
show as action means show icon
never means stash it in all others that not fit in scree
n -->
<item android:id="@+id/action_vibration"
android:icon="@drawable/small_vibration_button_on"
android:title="@string/action_vibration"
app:showAsAction="always"/>
<item android:id="@+id/action_openfile"
android:title="@string/action_openfile"
app:showAsAction="never"/>
<item android:id="@+id/action_exitplay"
android:title="@string/action_exitplay"
android:visible="false"
app:showAsAction="always"/>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
</menu>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">#f2f2f2</color>
<color name="primary_dark">#f2f2f2</color>
<color name="accent">#D9D9D9</color>
<color name="text_primary">#D9000000</color>
<color name="text_secondary">#D9000000</color>
<!--
original from example(blue),(my is light gray header and light gray body):
<color name="primary">#673ab7</color>
<color name="primary_dark">#512da8</color>
<color name="accent">#ffc400</color>
<color name="text_primary">#D9FFFFFF</color>
<color name="text_secondary">#D9000000</color>
-->
</resources>
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 21 theme customizations can go here. -->
<item name="android:navigationBarColor">@color/primary_dark</item>
</style>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.