[英]Android studio 3.1.4 toolbar stuck in corner
很难解释-但是我尝试在项目中添加的所有工具栏似乎都停留在角落。
我做了一个测试布局以清楚地显示它:测试蓝图工具栏
单击图像查看大图。
这是xml:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="1000dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</LinearLayout>
我尝试使用不同的布局。 也无法拖动工具栏来调整其大小。
和代码
<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/auth_request_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AuthRequestActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/activity_auth_request_toolbar"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_alignParentTop="true"
android:background="@color/somecompanycolor"
android:minHeight="@dimen/toolbar_height"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<fragment
android:id="@+id/activity_auth_request_fragment"
android:name="someexternalsdk"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_below="@id/activity_auth_request_toolbar" />
</android.support.constraint.ConstraintLayout>
我设置工具栏的代码:
mToolbar = findViewById(R.id.activity_auth_request_toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("Request");
有关更多信息,我的目标是28.0.0-rc02,最大sdk版本28,最小15。
有人知道我在做什么错吗?
编辑1
这似乎是Android 28.0.0-rc02上的错误
在build.gradle中降级27并依赖build.gradle
将解决此问题
原始答案
您使用的是ConstraintLayout
但视图不受限制
这是通常在未定义任何约束时android studio向我们显示的警告
此视图不受限制。 它只有设计时位置,因此它将在运行时跳至(0,0)
像这样定义工具栏的约束
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main2Activity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
我也遇到过类似的问题,主要是在使用受限布局时。 典型的错误是
与您在帖子中描述的问题非常共鸣。 查看下面的图像,如果遇到类似的问题,请还原。
同样,也查找“渲染问题”。
解:
我会尝试@Ashwini Violet提出的建议。
另外,我建议您检查styles.xml
文件。 如果您有以下内容
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
我建议更改为
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
这里的关键词是Base
尝试这些,如果需要更多帮助,请返回。 H
以下是一些过去对我有帮助的参考。
参考文献:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.