3

there are many questions regarding this but not even single helped me.

So please tell me how to enable material design features in eclipse.

i have also imported appcompat_v7 library in project but it does not create a folder with name values_v21 which helps in using those feature i think.

So please help me out in this

here is my styles.xml file

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/AppTheme_ActionBar</item>
        <item name="android:actionBarSize">@dimen/action_bar_height</item>
        <item name="android:windowContentOverlay">@drawable/actionbar_shadow</item>
        <item name="android:homeAsUpIndicator">@drawable/ic_ab_up_compat</item>
       <item name="android:actionBarTabTextStyle">@style/tabtextcolor</item>
        <item name="android:actionOverflowButtonStyle">@style/AppTheme_ActionBar_Overflow</item>
    </style>

    <style name="AppTheme_ActionBar" parent="android:Widget.Holo.ActionBar.Solid">
        <item name="android:background">@color/apptheme_primary</item>
         <item name="android:actionBarTabTextStyle">@style/tabtextcolor</item>
        <item name="android:icon">@drawable/actionbar_icon_placeholder_compat</item>
        <item name="android:titleTextStyle">@style/AppTheme_ActionBar_Title</item>
    </style>

    <style name="AppTheme_ActionBar_Title" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textColor">@android:color/white</item>
        <item name="android:textSize">20sp</item>
    </style>

    <style name="AppTheme_ActionBar_Overflow" parent="android:Widget.ActionButton.Overflow">
        <item name="android:src">@drawable/ic_ab_overflow_compat</item>

    </style>


    <style name="tabtextcolor" parent="@android:style/Widget.Holo.Light.ActionBar.TabText">
    <item name="android:textColor">@android:color/white</item>
</style>
</resources>
Android
  • 109
  • 1
  • 8

2 Answers2

3

There are some points you should check:

  • Import into eclipse, last version of android-support-v7-appcompat project. You should update via SDK Manager, and import project from {your_path_to_android_sdk}/extras/android/support/v7/appcompat
  • Add this project as library dependency to your project
  • In styles.xml use Theme.AppCompat.Light or Theme.AppCompat:

    style name="AppTheme" parent="@style/Theme.AppCompat.Light"

Dr.jacky
  • 3,341
  • 6
  • 53
  • 91
Álvaro Pérez Soria
  • 1,443
  • 1
  • 13
  • 26
  • but importing this library does not create folder values-v21 or it does not matter , can you tell me the complete changes i need to do in styles.xml after importing this library? – Android Mar 11 '15 at 09:00
  • No, importing this library does not create values-v21 itself. This folder, if exists in an Android Application, is used for Api-Level 21 devices, so if you intend to use material design only in lower level devices, you don't need this folder. If you need both, then you should create separate folders for each API level – Álvaro Pérez Soria Mar 11 '15 at 09:27
  • when i change themes to theme.appcompat it deletes my r file – Android Mar 11 '15 at 09:28
  • how are you importing appcompat library? It is not enough, just adding jar file into libs folder. You should import it as Android library (Project Properties-> Android -> library) – Álvaro Pérez Soria Mar 11 '15 at 09:32
  • yes i am doing same. actually i wanna create a floating action button on my listview. bu it always show error in eclipse. here is the xml line in which i am changing theme to appcompat name="AppTheme" parent="android:Theme.AppCompat.Light.DarkActionBar" – Android Mar 11 '15 at 09:39
  • try name="AppTheme" parent="@style/Theme.AppCompat" (change android namespace with @style) – Álvaro Pérez Soria Mar 11 '15 at 10:43
  • changed but still getting error in action bar while running project. i have added my styles.xml file in question on top. – Android Mar 11 '15 at 10:56
  • on creating action bar. like some where i have used getActionbar().hide and i am getting null pointer exception there because there is nothing to hide(there is no action bar) – Android Mar 11 '15 at 11:15
  • when dealing with actionbar you should use getSupportActionBar() – Álvaro Pérez Soria Mar 11 '15 at 11:29
  • i am getting only getActionbar i cant see getsupportactionbar() – Android Mar 11 '15 at 11:54
  • your activity must extend ActionBarActivity – Álvaro Pérez Soria Mar 11 '15 at 12:00
  • Thanks man i got it working. could you do me a favour.... Can you refer a link to use material widgets like floating button and all in eclipse. – Android Mar 11 '15 at 12:13
  • Thanks: the key point from your answer that helped me is *Add this project as library dependency to your project*. I had already added the project to the java build path, but overlooked the android dependency paths – dsh Nov 12 '15 at 20:53
0

A simple guideline:

  • import the appcompat-v7 project and add it as a library dependency for your project
  • let your theme inherit some of the appcompat themes. For example <style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
  • Note that not all widgets (ui elements) are material-styled by appcompat
  • Follow the examples and explanations in the android-developers blogspot.
  • The values-vXY folders are used to add specific resources for a specific platform. For example you might add a style (in a values-v21 folder) that inherits some of the material styles that are built-in and available only one api level 21+. These folders are created manually and are only used if you want an alternative resource for a specific platform level. They are used when you want your app to fit better in all/many android versions. More info - at the android developers portal
stan0
  • 11,549
  • 6
  • 42
  • 59