[英]ConstraintLayout behaves strange on Android L device
I'm using ConstraintLayout for the layout of a dialog fragment.我将 ConstraintLayout 用于对话框片段的布局。 It's all good except on the device with Android Lollipop.
除了在带有 Android Lollipop 的设备上之外,一切都很好。 There, the layout adds up a textView(id/title) automatically on the top which is not even declared in the layout.
在那里,布局会在顶部自动添加一个 textView(id/title),它甚至没有在布局中声明。 When I run Layout Inspector, I get following results:
当我运行 Layout Inspector 时,我得到以下结果:
Here I fail to understand why it's happening.在这里,我不明白为什么会发生这种情况。 Here is my layout's xml code.
这是我的布局的 xml 代码。 Appreciate your help.
感谢你的帮助。
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/black_overlay"
android:layout_width="325dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvTitle"
style="@style/TextAppearance.Black"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="25dp"
android:maxLines="2"
android:text="@string/signup_alert_title"
app:layout_constraintEnd_toStartOf="@+id/ivDismissDialog"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/ivDismissDialog"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginTop="19dp"
android:layout_marginEnd="19dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_cancel_deselected" />
<TextView
android:id="@+id/tvSignupDetails"
style="@style/TextAppearance.Regular"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:text="@string/signup_alert_details"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvTitle" />
<Button
android:id="@+id/signupButton"
style="@style/Button.FilledButton"
android:layout_width="208dp"
android:layout_height="wrap_content"
android:layout_marginStart="62dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="55dp"
android:text="@string/signup"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvSignupDetails" />
<Button
android:id="@+id/loginButton"
style="@style/Button.FlatButton"
android:layout_width="208dp"
android:layout_height="wrap_content"
android:layout_marginStart="62dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="55dp"
android:layout_marginBottom="24dp"
android:text="@string/login"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/signupButton" />
</androidx.constraintlayout.widget.ConstraintLayout>
This is basically theme related.这基本上是与主题相关的。 In android the root view in most cases is a
FrameLayout
and using a theme like Theme.AppCompat.Light.DarkActionBar
can add an extra view to the ViewGroup
to display an actionbar with title.在 android 中,大多数情况下的根视图是
FrameLayout
并且使用像Theme.AppCompat.Light.DarkActionBar
这样的主题可以向ViewGroup
添加额外的视图以显示带有标题的操作栏。
The typical default actionBar code looks like below:典型的默认 actionBar 代码如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/title"
android:text="YOUR ACTIVITY TITLE"
android:textColor="#ffffff"
android:textSize="24sp" />
</LinearLayout>
This simply means we can access the predefined textview using a reference like below if it exists:这只是意味着我们可以使用如下引用访问预定义的文本视图(如果存在):
View decor = getWindow().getDecorView();
TextView title = (TextView) decor.findViewById(getResources().getIdentifier("title", "id", "android"));
In other to get read of the action bar or textview overall we use a different app theme that requires no action bar or we add the below options to app's parent/base theme under style:在其他方面为了整体阅读操作栏或文本视图,我们使用不同的应用主题,不需要操作栏,或者我们将以下选项添加到应用的父/基本主题样式下:
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.