Android ActionBarCompat库

Mic*_*hal 13 android android-studio android-actionbar-compat

我在使用昨天发布的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.+')}
Run Code Online (Sandbox Code Playgroud)

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

我究竟做错了什么?谢谢.

Hel*_*den 9

我正在使用Android Studio,而且我在我的问题上有同样的res解决问题values/styles.xml.

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

我想摆脱res无法解决的警告.

如何告诉Android Studio可以在appcompat-v7 repo中找到此res?
(此问题与Android Studio中已修复的错误有关.)


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

Gradle集成:

dependencies {
    ...
    compile group:'com.android.support', name:'appcompat-v7', version:'18.0.+'
    ...
}
Run Code Online (Sandbox Code Playgroud)

样式文件:

价值观/ 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>
Run Code Online (Sandbox Code Playgroud)

值-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>
Run Code Online (Sandbox Code Playgroud)

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

public class MainActivity extends ActionBarActivity {

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

        setupNavigationDrawer();
    }
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)


ree*_*ece 7

有一个已知错误(http://code.google.com/p/android/issues/detail?id=56312),其中Android Studio IDE会将样式标记为红色(该错误适用于ActionBarSherlock,但问题是与包含样式的aar以及Android Studio不可见的源代码相关联.

具体而言,评论#8(http://code.google.com/p/android/issues/detail?id=56312#c4)显示观察到的行为,并发表评论#10(http://code.google.com/ p/android/issues/detail?id = 56312#c10)注意到布局编辑器是固定的,但代码编辑器不是.

因此,程序应该构建并运行正常,只需在XML样式编辑器中查看时以红色显示样式.


Vip*_*hah 2

我还没有尝试过 Gradle,所以我不确定,但似乎你还需要将资源复制到你的项目中。它包含 Theme.AppCompat。

我按照以下步骤在 Eclipse 中取得了成功。

从下面的路径导入android-support-v7-appcompat为 libray 项目。(您可能已将 sdk 保存在不同的路径上)

D:\adt-bundle-windows-x86\adt-bundle-windows-x86\sdk\extras\android\support\v7

我刚刚将此库添加到我的项目中,一切都开箱即用。