简体   繁体   English

Android studio v1 - 动作栏未显示

[英]Android studio v1 - actionbar not showing

I've been using the beta version until now. 我一直在使用测试版。 Now that I've upgraded to v1, any new project that I start doesn't show the actionbar in the design view. 现在我已升级到v1,我启动的任何新项目都没有在设计视图中显示操作栏。 Is there a workaround? 有解决方法吗? It shows up fine on the devices I'm testing it on put just doesn't show in the design mode. 它在我正在测试的设备上显示正常,只是在设计模式下没有显示。 The only thing different on the device compared to before is that the app icon doesn't show on the actionbar. 与之前相比,设备上唯一不同的是应用程序图标未显示在操作栏上。

Solved: The issue was due to the theme. 解决:问题是由于主题。

Won't show the icon and doesn't show the action bar in the design editor: 不会显示图标,也不会在设计编辑器中显示操作栏:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

Will show the icon and action bar in the design mode 将在设计模式中显示图标和操作栏

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">

Android Studio by default creates new Application with Appcompat-v7 . Android Studio默认使用Appcompat-v7创建新的应用程序。 So your application theme was Theme.AppCompat.Light.DarkActionBar . 所以你的应用程序主题是Theme.AppCompat.Light.DarkActionBar And Material design does not support ActionBar . 而Material Design不支持ActionBar And that is the reason that you cannot see ActionBar as well as App icon in design view. 这就是你无法在设计视图中看到ActionBar和App图标的原因。 If you want ActionBar like functionality then you can use toolbar . 如果您想要ActionBar类的功能,那么您可以使用toolbar

By changing theme to android:Theme.Holo.Light.DarkActionBar solves issue but then your app will not be created with material design. 通过将主题更改为android:Theme.Holo.Light.DarkActionBar解决了问题,但之后您的应用程序将不会使用材质设计创建。 (Choice is upto you). (选择取决于你)。

Inside your AndroidManifest.xml 在你的AndroidManifest.xml里面

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

You have to make sure the android:theme line isn't saying .NoActionBar 你必须确保android:theme line不是说.NoActionBar

use this code 使用此代码

   <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/primary</item>

</style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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