Krz*_*mic 22 user-interface android android-layout android-4.4-kitkat
我正在尝试利用新的KitKat半透明系统条,在我的应用程序的背景中获得全屏图像.
我在找出正确的设置以获得我想要的行为时遇到了问题.现在我有ViewPager三个Fragments,每个RelativeLayout包含一个ImageView(用于背景图像)和一个TextView用于内容.
我所追求的是让内容完全适合可用于交互的屏幕部分,并使图像占据屏幕的整个可见部分.
如果我只是android:Theme.Holo.Light.NoActionBar.TranslucentDecor用作我的主题,它在纵向看起来很好,但导航栏与横向内容重叠(请参见下面的屏幕截图).


按照文档中的建议,我添加android:fitsSystemWindows = true到我的主题,但这会产生一些奇怪的文物(见下文)

我怎样才能使它在第二个例子中表现得像,但看起来不错,没有视觉文物?
Tan*_*ien 39
我的解决方案是在横向模式下禁用半透明导航.您仍然可以获得半透明的状态栏,但它解决了导航栏不透明并且在横向上重叠的问题.
res/values-v19/styles.xml (这些值在我的主题中)
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">@bool/translucentNavBar</item>
Run Code Online (Sandbox Code Playgroud)
res/values-v19/bools.xml (启用半透明导航)
<bool name="translucentNavBar">true</bool>
Run Code Online (Sandbox Code Playgroud)
res/values-land-v19/bools.xml (在横向上禁用半透明导航)
<bool name="translucentNavBar">false</bool>
Run Code Online (Sandbox Code Playgroud)
res/values-sw600dp-land-v19/bools.xml (为横向平板电脑启用半透明导航)
<bool name="translucentNavBar">true</bool>
Run Code Online (Sandbox Code Playgroud)
我知道这已经过时了,但是我遇到了同样的问题并且发现了一个简单的解决方案,所以我想分享它以防万一谷歌遇到这种情况.
当ViewPager(尤其是ImageSwitcher)放置在具有该属性的布局中时,似乎存在Android错误android:fitsSystemWindows="true".由于某种原因,系统窗口似乎正在获取遍布它们的工件.:/
无论如何,我发现了一个修复.对于我的活动,我有一个XML布局如下:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
<!-- NOT HERE! android:fitsSystemWindows="true" -->
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageSwitcher
android:id="@+id/background_image_switcher"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
android:layout_margin="0dp"
android:background="@color/background_dark_navy"
android:inAnimation="@android:anim/fade_in"
android:outAnimation="@android:anim/fade_out"
>
<ImageView
style="@style/BlurredBackgroundImage"
/>
<ImageView
style="@style/BlurredBackgroundImage"
/>
</ImageSwitcher>
<FrameLayout
android:fitsSystemWindows="true" <!-- Here!!! -->
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Fitted content here -->
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
诀窍是不在包含android:fitsSystemWindows="true"属性的布局中包含ImageSwitcher,而是将android:fitsSystemWindows="true"属性移动到包含我需要适合的实际内容的内部 FrameLayout(在您的情况下为标题文本).不幸的是,这允许ImageSwitcher/ViewPager的视图被系统窗口略微切断,但是如果图像像背景图像一样使用它无关紧要并且比工件或维护所有更好的权衡可能有也可能没有禁用导航的不同尺寸/样式(例如当前选择的答案).
我希望这可以帮助别人!
| 归档时间: |
|
| 查看次数: |
20007 次 |
| 最近记录: |