我从android studio开始,我无法看到元素(Buttons,TextView,..),我在activity_main.xml
页面的“设计”页面中拖放。这些元素存在于我的XML文件中,当我在设备上运行我的应用程序时,我可以看到它们,但我不知道如何在“设计和蓝图”中找到它们。页。
感谢您的帮助。
这是我的xml代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:layout_editor_absoluteY="25dp">
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_home"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="@menu/navigation" />
<Button
android:id="@+id/button"
android:layout_width="12dp"
android:layout_height="12dp"
android:text="ClickMe"
tools:layout_editor_absoluteX="-73dp"
tools:layout_editor_absoluteY="29dp" />
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="20dp" />
</android.support.constraint.ConstraintLayout>
我的画布完全是空的。
编辑:
我有2个错误:
渲染问题:Failed to find style 'bottomNavigationStyle' in current theme Tip: Try to refresh the layout.
ConstraintLayout中缺少约束:
This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints
答案 0 :(得分:17)
您可以通过修复styles.xml文件来解决此问题。
然后您只需要在此代码中添加Base:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
最终代码:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
答案 1 :(得分:3)
如果您遇到与此页面相同的错误,则应在com.android.support:appcompat-v7:28.0.0-alpha3
中将com.android.support:appcompat-v7:28.0.0-alpha1
更改为build.gradle(Module: app)
,然后点击文件 - &gt;使高速缓存/重新启动无效。现在一切都好。
当然,您需要访问互联网才能下载com.android.support:appcompat-v7:28.0.0-alpha1
答案 2 :(得分:2)
答案 3 :(得分:1)
要解决此问题:
答案 4 :(得分:0)
1)尝试使用顶部
中的构建菜单中的选项来清理项目2)通过选择“文件”菜单中的选项
,尝试使Android Studio无效并重新启动3)尝试通过选择顶部
中的构建菜单中的选项重建项目答案 5 :(得分:0)
我已经解决了问题:
我的build.gradle文件:
dependencies {
api 'com.android.support:appcompat-v7:28.0.0-alpha1'
api 'com.android.support:design:28.0.0-alpha1'
api 'com.android.support.constraint:constraint-layout:1.1.2'
api 'com.android.support:support-vector-drawable:28.0.0-alpha1'
application project(':app')
feature project(':feature')
}
我用&#34; alpha3&#34;改变了所有的行。 by&#34; alpha1&#34;。 谢谢@ hossein-seifi
答案 6 :(得分:0)
在值中找到Styles.xml
。(res >> Values >> Styles.xml)更改
添加“基本”
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to this:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
然后清理并构建项目。您都可以在构建菜单中完成这两项操作。
对我有用。
答案 7 :(得分:0)