0

I have my activity with an action bar which I want to customize, however Android is ignoring all my styles...

This is how it looks now:

Current appearance

It should look with a blue background instead and the application logo should be there also...

My manifest is the following:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="greensmartcampus.eu.smartcampususerfeedbackapp">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:logo="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/SmartCampusTheme">
        <!-- Splash screen while connecting to the web-server -->
        <activity
            android:name=".HomeScreen"
            android:label="@string/title_activity_home_screen"
            android:parentActivityName=".AbstractPortraitActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="greensmartcampus.eu.smartcampususerfeedbackapp.AbstractPortraitActivity" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!-- The activity where all actions take place -->
        <activity
            android:name=".ControlActivity"
            android:label="@string/title_activity_control"
            android:parentActivityName=".AbstractPortraitActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="greensmartcampus.eu.smartcampususerfeedbackapp.AbstractPortraitActivity" />
        </activity>
    </application>

</manifest>

My activity xml is the following:

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="greensmartcampus.eu.smartcampususerfeedbackapp.ControlActivity" />

My styles.xml is the following:

<resources>

    <!-- Base application theme. -->
    <style name="SmartCampusTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/CustomActionBarTheme</item>
    </style>

    <style name="GenericProgressIndicator" parent="@android:style/Widget.ProgressBar.Small">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:indeterminate">true</item>
    </style>

    <style name="CustomActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@color/actionbar_bg_color</item>
    </style>

</resources>

I also want to hide those 3 dots in the action bar which open the menu to the settings, which I don't have...

Settings button

What am I doing wrong?

Thanks!

PedroD
  • 5,670
  • 12
  • 46
  • 84

2 Answers2

1

I believe your issue is related to using the app compatibility library. Try removing the android: prefix from your Actionbar styles. See Styling the Action Bar and appcompat v21.

Chris Feist
  • 1,678
  • 15
  • 17
1

AppCompat v21 brings the Material theme to all devices. Two changes with this is the use of the new color palette for theming your action bar and activity. In the new system, coloring your action bar is accomplished via a theme such as:

<style name="SmartCampusTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/actionbar_bg_color</item>
</style>

In addition, the lack of the app icon is expected. Per the Toolbar documentation:

In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.

The action bar showing a 'Settings' option is part of the initial template - you can delete the onCreateOptionsMenu method to remove all items from the options menu.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • But I really need to put the icon there, how can I do it (in the xml)? For example this topic suggest a non-style-xml way of doing it: http://stackoverflow.com/questions/26440279/show-icon-in-actionbar-toolbar-with-appcompat-v7-21? – PedroD Feb 06 '15 at 12:12
  • About the "onCreateOptionsMenu" method, is there a way to do it in the style.xml (making the method return false or removing it worked as you said)? I really didn't want to mix styles with the code (MVC). – PedroD Feb 06 '15 at 12:17
  • I am still struggling to find a way to put the icon there, android:background or just background don't work... :( – PedroD Feb 06 '15 at 12:26