【问题标题】:Android view not shown on device设备上未显示 Android 视图
【发布时间】:2017-03-10 12:18:59
【问题描述】:

我有一个布局文件,用于在屏幕底部显示一些信息。在过去的一年中,这一直在按预期工作。但是最近我意识到文本不再显示。这是我的 xml:

<RelativeLayout 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:background="@color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="nl.l1nda.contactinfo.ContactInfoActivity">


    <TextView
        android:id="@+id/appVersionText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_alignParentBottom="true"
        android:padding="@dimen/activity_margin"
        android:text="Some text here"
        android:background="@color/colorAccent"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@color/black_overlay" />
</RelativeLayout>

这在设计视图中显示如下:

但是在运行应用程序时,文本只是不显示:

但是请注意,视图是存在的,因为将其大小设置为 90dp 会显示以下内容:

相对布局的行为是否发生了某种变化?

编辑:根据要求,styles.xml:

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColor">@drawable/text</item>
    </style>

    <style name="ThemeDialog" parent="Theme.AppCompat.Light.Dialog">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowFullscreen">false</item>
    </style>

    <style name="AppTheme.Launcher" parent="AppTheme.NoActionBar">
        <item name="android:background">@color/black_overlay_dark</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="android:textColor">@color/colorPrimaryDark</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
        <item name="colorControlNormal">@color/white</item>
    </style>

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

    <style name="FullscreenTheme" parent="AppTheme">
        <item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
        <item name="android:windowActionBarOverlay">true</item>
        <item name="android:windowBackground">@null</item>
        <item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
        <item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
    </style>

    <style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
        <item name="android:background">@color/black_overlay</item>
    </style>

</resources>

【问题讨论】:

  • 把你的style.xml代码
  • 您是否在此活动中的任何位置为半透明状态栏设置了标志?你的风格还可以
  • @RajeshKushvaha 我什么地方都没有。
  • 我回答 &lt;item name="android:windowDrawsSystemBarBackgrounds"&gt;true&lt;/item&gt; 这会解决您的问题,您尝试了吗?
  • @RajeshKushvaha 已经在我的第 21 版的 styles.xml 中了。没有区别。

标签: android android-layout android-relativelayout


【解决方案1】:

只需在 style.xml v-21 中添加这个

<item name="android:fitsSystemWindows">true</item>
<item name="android:windowTranslucentNavigation">true</item><-this can be ignore
<item name="android:windowDrawsSystemBarBackgrounds">true</item>

【讨论】:

  • 这不是我想要的。我希望我的相对布局适合可用空间。
【解决方案2】:

这里的答案似乎都没有帮助我做了一些进一步的研究,我设法通过在我的活动中添加以下内容来解决它:

 AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
 params.setScrollFlags(0);

【讨论】:

    【解决方案3】:

    我在升级到 android Nougat 时遇到了同样的问题,我最近使用下面的代码 sn-p 解决了它。

    请在manifest 中输入fitsSytemWindow=true 进行您的活动。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-20
      • 2012-09-10
      • 2012-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多