简体   繁体   中英

Android Studio: Trouble specifying drawable resource

I am trying to specify an menu icon for an Action Bar. I'm using Android Studio 1.2. My XML code follows:

<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=".MainActivity">
    <item
        android:id="@+id/menu_connect"
        android:icon="@drawable/ic_settings_bluetooth_white_24dp.png"
        android:title="@string/menu_connect"
        app:showAsAction="always"
        />
    <item
        android:id="@+id/menu_settings"
        android:title="@string/menu_settings"
        app:showAsAction="never"
        />
</menu>

The compiler complains about anything that I put after "android:icon=". Depending on what I've changed last, I get: "No resource found that matches the given name" or "String types not allowed" (among other errors).

I've tried suggestions from several posts. I cleared the Intellij cache and rebuilt everything and nothing changed. One post suggested that perhaps android:icon wasn't supported in earlier API versions so I set minSdkVersion to 23 (my current SDK version) in my module build script. I re-sync'd and again nothing changed.

I had some trouble figuring out how to set up the drawable directories for multiple resolution bitmaps. (Why doesn't Android Studio just create them when creating a new project?) I now have them (drawable-hdpi etc.) set up as siblings to the drawable directory. I think that's right. At least they appear to be correct in the Android directory view. Yeah, I'm a newbie.

Is there anything else that I can try?

Replace:

android:icon="@drawable/ic_settings_bluetooth_white_24dp.png"

with:

android:icon="@drawable/ic_settings_bluetooth_white_24dp"

You do not use file extensions when referring to resources from anywhere inside of Android.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM