簡體   English   中英

錯誤:不允許使用字符串類型

[英]Error:String types not allowed

我是android的新手。 我面臨以下錯誤: 不允許字符串類型

編輯 :我在參考資料中保留了image.jpg - > drawwble- hdpi

請參閱以下代碼: Strings.xml

 <drawable name="test_image">image.jpg</drawable>

activity_main.xml中

<ImageView android:id="@+id/imageDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/desc" 
android:src="@drawable/test_image" />

ANDROID_MANIFEST

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

你可以這樣做:

<ImageView android:id="@+id/imageDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/desc" 
android:src="@drawable/image" />

@drawable/image代表你的drawable名為“image”。

  1. 將圖像放在res/drawable文件夾中。
  2. 還刪除文件擴展名。

我希望有所幫助。

android:src屬性的值應該是一個可繪制的對象。 所以你應該把文件'image.jpg'放到你的Android項目的文件夾res / drawable /中,然后替換這行:

android:src="@drawable/test_image"

android:src="@drawable/image"

這將引用您放置在drawable文件夾中的文件'image.jpg'。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM