【问题标题】:AndroidX Toolbar is mis-locatedAndroidX 工具栏位置错误
【发布时间】:2018-12-14 14:53:33
【问题描述】:

我正在为我的 Android 项目使用 AndroidX 依赖项。

我的活动中有一个Toolbar(此活动是为了通过支付一些钱来支持开发人员)包裹在这样的线性布局中:

<LinearLayout
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"
android:orientation="vertical"
android:background="@drawable/gradient"
tools:context=".Support">

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar_support"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@null"
    app:popupTheme="@style/AppTheme.PopupOverlay" />

</LinearLayout>

使用的其他XML代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
android:background="@drawable/gradient"
tools:context=".Support">

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar_support"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@null"
    app:popupTheme="@style/AppTheme.PopupOverlay" />

<TextView
    android:layout_marginTop="150dp"
    android:layout_marginStart="10dp"
    android:layout_marginEnd="10dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:fontFamily="@font/google_sans"
    android:textSize="17dp"
    android:textColor="#ffffff"
    android:text="@string/support_para"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="#ffffff"
        android:textSize="20dp"
        android:text="$"/>

    <EditText
        android:id="@+id/amount"
        android:layout_width="270dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:hint="@string/pay_amount"
        android:textColorHint="#ffffff"
        android:textSize="20dp"
        android:layout_marginStart="10dp"
        android:layout_gravity="end"
        android:maxLines="1" />
</LinearLayout>

<Button
    android:id="@+id/googlepay"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="30dp"
    android:background="@drawable/round_button"
    android:textColor="#ffffff"
    android:fontFamily="@font/google_sans"
    android:text="@string/pay"/>

</LinearLayout>

现在我得到的是:

【问题讨论】:

  • 我删除了你的弹出主题,它看起来不错,请尝试删除它。可能有一些价值会导致这种情况。
  • @KaranMer 你的评论似乎对我不起作用,popup theme in styles.xml: &lt;style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /&gt;

标签: android-linearlayout android-xml androidx


【解决方案1】:

我得到了我自己问题的答案!
我的Support.java 文件中有一行:

toolbar.bringToFront();

我刚刚删除了它,它帮助了我

【讨论】:

  • 但我不知道为什么这会导致工具栏错位?
猜你喜欢
  • 2017-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多