2015-08-28 87 views
1

我想要为Android 4.2设备编程,但我拥有的书是教Android 4.0叫Beginning Android App Development 4。所以,我有针对性运行于Android 4.2的第一个程序问题:Android 4.0 vs 4.2 API差异

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/ 
android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="This is my first Android Application!" /> 

    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="And this is a clickable button!" /> 

</LinearLayout> 

error: Error: No resource found that matches the given name (at 'text' with value '@string/hello'). activity_main.xml /HelloWorld/res/layout line 7 Android AAPT Problem

[I18N] Hardcoded string "And this is a clickable button!", should use @string resource activity_main.xml /HelloWorld/res/layout line 20 Android Lint Problem

[I18N] Hardcoded string "This is my first Android Application!", should use @string resource activity_main.xml /HelloWorld/res/layout line 15 Android Lint Problem

我想我在哪里可以找到从4.2 4.0 API之间的差异?我应该继续阅读这本书吗?

回答

1

那么,第一个错误是因为您尚未在您的strings.xml中创建一个名为hello的资源。另外两个警告只是因为Android Lint希望您使用字符串资源(如第一个),而不是硬编码字符串。

但是,这些与Android 4.0和4.2之间的任何差异都没有任何关系。

如果您仍然对这些API级别的差异感到好奇,Android文档提供了大量信息。

https://developer.android.com/sdk/api_diff/21/changes.html https://developer.android.com/sdk/api_diff/22/changes.html

+0

谢谢,看起来这本书假定你是一个专业版而不是一个初学者,它充斥着大量的代码,几乎没有任何解释,任何关于更改本书的建议? – user963241

+0

我个人没有阅读任何有关Android的书,所以我无法帮助你。是通过提供的教程和文档,因为它们实际上很彻底。https://developer.android.com/training/index.html –

1

您的问题IST不是真的有问题API'S它只是因为你使用的字符串,是不是在strings.xml档案(硬编码字符串)。你可以忽略它(应该只是一个建议而不是一个错误),或者只是创建一个字符串(只有当你不止一次地使用该字符串时)