Search code examples
androidandroid-layoutandroid-viewandroid-themeandroid-styles

Duplicating items with android:


Trying to setup my app to use Material design:

<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

        <item name="android:colorPrimary">@color/colorPrimary</item>
        <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:colorAccent">@color/colorAccent</item>
  • If items with android: are removed - the colors are not getting applied.
  • If items without android: are removed - app crashes:

Unable to start activity ComponentInfo{com.foo.bar/com.foo.bar.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.design.widget.TabLayout

Questions:

  • Why do I have to duplicate those?
  • Should I duplicate all styles like that?

EDIT:

The Manifest file is:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.foo.bar">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

EDIT2

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.TabLayout
        android:id="@+id/tl_periods"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMinWidth="100dp"
        app:tabMode="scrollable"/>

Solution

  • The theme of your application is not a descendant of AppCompat theme, whereas your TabLayout is from support packages.

    You either have to stick with AppCompat theme and views, or entirely be support packages independent, otherwise such nasty issues will rise.