android-studio - 工具栏未在 android studio 预览中显示
问题描述
Android 工具栏不显示在 android studio 中,但它显示在设备上。我跟踪了很多主题,但没有具体的解决方案。我在 android 上创建了一个新项目,但无论如何都没有显示。也没有显示我的旧项目。
设备
我也收到这些错误
渲染问题
加载 AppCompat ActionBar 失败,出现未知错误。提示:尝试刷新布局。
无法实例化一个或多个类
无法实例化以下类: - android.support.v7.widget.ActionBarContainer(打开类,显示异常,清除缓存) - android.support.v7.widget.ActionBarContextView(打开类,显示异常,清除缓存) - android .support.v7.app.WindowDecorActionBar(打开类、显示异常、清除缓存) 提示:在自定义视图中使用 View.isInEditMode() 可跳过代码或在 IDE 中显示示例数据。
但是当我添加“Base”时,这些问题并没有显示出来。里面的风格apptheme。
到目前为止我做了什么
有人说这是关于“com.android.support:appcompat-v7:28.0.0”所以使用“com.android.support:appcompat-v7:28.0.0-alpha1”但它没有用。我也试过用alpha3 .
我在 style.xml 上更改了 apptheme 我尝试了“NoActionBar”、“Dark.ActionBar”等等。但没有任何改变。
清除缓存,但没有用。
我在 style.xml (apptheme) 中添加了“.Base”。
主要活动
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
</android.support.constraint.ConstraintLayout>
摇篮
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.test.parala"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
摇篮2
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
显现
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.parala">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
风格
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="koko" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:actionBarSize">40dp</item>
</style>
解决方案
这可能不是完全正确的答案。但对于任何其他情况都是实用的。下载你的 gradle v27。这样工具栏就会出现在布局管理器上,然后在发布项目之前再次升级到 v28。
推荐阅读
- django - 浏览器返回按钮后刷新 Django 向导表单
- android - 在 app.json 中为 Android 的 app.json 中的 CAMERA_ROLL 添加什么权限?
- python - 名称错误。,通过四阶龙格库塔算法求解耦合微分方程时
- javascript - 警告:类型模块中未定义属性命令:“discord.js”.Client
- node.js - Nodejs如何处理可能会在它们之间产生冲突的多个请求?
- c# - Mailchimp API 成功指示器
- javascript - 你如何在 React 中选择一个特定的项目/组件,然后在 onClick 数组中循环?
- java - 在recyclerview android studio中动态显示按钮
- powershell - Powershell 中的 Selenium 在 Start-Job 中无法正常工作
- node.js - Mongoose:使用对象数组查找所有模型