Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Attrs for ExpandCards #40

Closed
BradleyRL opened this issue Dec 2, 2013 · 3 comments
Closed

Using Attrs for ExpandCards #40

BradleyRL opened this issue Dec 2, 2013 · 3 comments

Comments

@BradleyRL
Copy link

I using a Light and Dark themes on my application also using the Expand Cards, but when im using a Dark Theme the ic_menu_expand_card_dark_normal is really hard to see, so i tried to use an attr in order to change the icon according to the theme

First I copied card_menu_button_expand.xml to my project and modified it like this

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/ic_menu_expand_card_dark_pressed"
      android:state_pressed="true"/>
<item android:drawable="@drawable/ic_menu_expand_card_dark_pressed"
      android:state_focused="true"/>
<item android:drawable="@drawable/ic_menu_expand_card_dark_pressed"
      android:state_selected="true"/>
<item android:drawable="?attr/info_icon"/>

my attrs.xml

<resources>
<attr name="info_icon" format="reference"/> 
</resources>

and my themes.xml

<style name="DarkTheme" parent="@android:style/Theme.Holo">
    <item name="info_icon" >@drawable/ic_menu_expand_card_light_normal"</item>

</style>

<style name="LightTheme" parent="@android:style/Theme.Holo.Light">
    <item name="info_icon" >@drawable/ic_menu_expand_card_dark_normal"</item>

</style>

But im getting a Force Close

12-02 14:43:23.650: E/AndroidRuntime(4555): FATAL EXCEPTION: main
12-02 14:43:23.650: E/AndroidRuntime(4555): android.view.InflateException: Binary XML file line #23: Error inflating class it.gmariotti.cardslib.library.view.CardView
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-02 14:43:23.650: E/AndroidRuntime(4555): at it.gmariotti.cardslib.library.internal.CardArrayAdapter.getView(CardArrayAdapter.java:142)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.widget.AbsListView.obtainView(AbsListView.java:2033)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.widget.ListView.makeAndAddView(ListView.java:1772)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.widget.ListView.fillDown(ListView.java:672)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.widget.ListView.fillFromTop(ListView.java:732)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.widget.ListView.layoutChildren(ListView.java:1625)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.widget.AbsListView.onLayout(AbsListView.java:1863)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.view.View.layout(View.java:11180)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.view.ViewGroup.layout(ViewGroup.java:4203)
12-02 14:43:23.650: E/AndroidRuntime(4555): Caused by: android.view.InflateException: Binary XML file line #40: Error inflating class it.gmariotti.cardslib.library.view.component.CardHeaderView
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-02 14:43:23.650: E/AndroidRuntime(4555): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-02 14:43:23.650: E/AndroidRuntime(4555): at it.gmariotti.cardslib.library.view.BaseCardView.initView(BaseCardView.java:153)
12-02 14:43:23.650: E/AndroidRuntime(4555): at it.gmariotti.cardslib.library.view.BaseCardView.init(BaseCardView.java:125)
12-02 14:43:23.650: E/AndroidRuntime(4555): at it.gmariotti.cardslib.library.view.BaseCardView.(BaseCardView.java:101)
12-02 14:43:23.650: E/AndroidRuntime(4555): at it.gmariotti.cardslib.library.view.CardView.(CardVi

Any input of what I'm doing wrong would be great or the lib doesn't support these?

@gabrielemariotti
Copy link
Owner

In my experience , it's not possible to correctly reference attributes in xml drawables.

@gabrielemariotti
Copy link
Owner

You can try this code:
attrs.xml

<resources>
       <attr name="info_icon" format="reference"/> 
</resources>

style.xml

<!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="info_icon">@drawable/your_selector1</item>
    </style>

    <style name="AppTheme2" parent="AppBaseTheme">
        <item name="info_icon">@drawable/your_selector2</item>
    </style>


    <!-- Button to Expand/Collapse in Header -->
    <style name="card.header_button_base.expand">
        <item name="android:background">?info_icon</item>
    </style>

Where drawable/your_selector1 and drawable/your_selector2 is a copy of card_menu_button_expand.xml.

<selector xmlns:android="http://schemas.android.com/apk/res/android">

 .....
<item android:drawable="@drawable/my_drawable1"/>
</selector>

@BradleyRL
Copy link
Author

awesome that actually worked 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants