gpt4 book ai didi

Android ActionBarCompat 库

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:21:19 25 4
gpt4 key购买 nike

我在使用昨天发布的 ActionBarCompat 支持库时遇到问题。我已经更新了支持存储库,并在 build.gradle 中包含了 appcompat-v7 存储库的路径,正如 Chris Banes 在 DevBytes 中指出的那样 - https://www.youtube.com/watch?v=6TGgYqfJnyc .

dependencies {
compile ('com.android.support:support-v4:18.0.+')
compile ('com.android.support:appcompat-v7:18.0.+')}

构建进展顺利,我可以使用该库中的类,例如 ActionBarActivity,但我不能使用样式和任何资源,所以我不能使用以下主题 - @style/Theme.AppCompat 等。我想我会找到源文件在 .../sdk/extras/android/.../"supportrepo"中,所以我会像 gradle 的 ActionBarSherlock 一样引用它,但这似乎不是正确的答案。

我做错了什么?谢谢。

最佳答案

我使用的是 Android Studio,我在 values/styles.xml 中遇到了同样的分辨率问题。

它说它无法解析@style/Theme.AppCompat.Light,但在编译时(gradle)和运行时一切正常(Android 2.3 .3 和 4.3)

我想去掉无法解析 res 的警告。

我如何告诉 Android Studio 这个资源可以在 appcompat-v7 存储库中找到?
(此问题与 Android Studio 中已修复的错误有关。)


下面你会看到我做了什么。我希望这将有所帮助。赞赏建议。
appcompat 库的源代码可以在 github 上找到.

Gradle 整合:

dependencies {
...
compile group:'com.android.support', name:'appcompat-v7', version:'18.0.+'
...
}

样式文件:

值/styles.xml:

<resources>

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
<item name="actionBarStyle">@style/ActionBar.Solid.Custom</item>
</style>

<style name="ActionBar.Solid.Custom" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">@drawable/ab_solid_custom</item>
<item name="displayOptions">homeAsUp|showHome|showCustom</item>
</style>

</resources>

values-v14/styles.xml:

<resources>

<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 14 theme customizations can go here. -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/ActionBar.Solid.Custom</item>
</style>

<style name="ActionBar.Solid.Custom" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">@drawable/ab_solid_custom</item>
<item name="android:displayOptions">homeAsUp|showHome|showCustom</item>
</style>

</resources>

MainActivity (只有扩展是必需的):

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Views.inject(this);

setupNavigationDrawer();
}
}

AndroidManifest.xml (必须设置 android:theme):

    <activity
android:name="com.example.app.MainActivity"
android:theme="@style/AppTheme"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

关于Android ActionBarCompat 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17856531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com