【问题标题】:Using settings fragment, the action bar covers up the top preference使用设置片段,操作栏覆盖了顶部偏好
【发布时间】:2013-05-15 20:19:15
【问题描述】:

我有一个简单的应用程序,它具有以片段样式实现的单页首选项。我在装有 Android 4.x(多个版本)的平板电脑上运行。当我打开首选项页面时,操作栏会覆盖顶部的首选项。我的解决方法是有一个虚拟的第一个项目,但这当然是愚蠢的。我只是不知道如何保留操作栏并将首选项从操作栏下方开始。我不是为操作栏编程,它只是显示出来。

Screen shot of problem

Preferences.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

    <CheckBoxPreference
        android:key="pref_AdaptToRoomXXX"
        android:title="This is the dummy item as a spacer" />

    <CheckBoxPreference
        android:key         ="@string/pref_TimeFormat"
        android:title       ="@string/action_setTimeFormat"
        android:summary     ="@string/action_setTimeFormat"
        />

    <ListPreference 
        android:key="@string/pref_DateFormat"
        android:title="@string/action_setDateFormat"
        android:summary="@string/action_setDateFormat"
        android:dialogTitle="@string/action_setDateFormat"
        android:entries="@array/action_setDateFormat_options"
        android:entryValues="@array/action_setDateFormat_values"
        android:defaultValue="@string/action_setDateFormat_default" />

    <ListPreference 
        android:key="@string/pref_TextColor"
        android:title="@string/action_setTextColor"
        android:summary="@string/action_setTextColor"
        android:dialogTitle="@string/action_setTextColor"
        android:entries="@array/action_setTextColor_colors"
        android:entryValues="@array/action_setTextColor_values"
        android:defaultValue="@string/action_setTextColor_default" />

    <CheckBoxPreference
        android:key="@string/pref_DimOnBattery"
        android:title="@string/action_setDimOnBattery"
        android:defaultValue="true" />

</PreferenceScreen>

有什么建议吗?

【问题讨论】:

    标签: android settings preferences


    【解决方案1】:

    通常您的ActionBar 不应覆盖内容。检查您是否为窗口设置了Window.FEATURE_ACTION_BAR_OVERLAY,即...

    requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    

    ... 在您的活动中被调用。如果是这样 - 删除它。

    希望这会有所帮助……干杯!

    【讨论】:

      【解决方案2】:

      我的解决方案是将app:layout_behavior 属性添加到布局文件中PreferenceFragment&lt;FrameLayout /&gt; 容器中。

      <FrameLayout
          android:id="@+id/fragment_container"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior" />
      

      【讨论】:

        【解决方案3】:

        通过将这两个属性添加到styles.xml中解决了我的问题

        <!-- Make setting content not covering by actionbar -->
        <item name="android:fitsSystemWindows">true</item>
        <item name="android:clipToPadding">true</item>
        

        【讨论】:

          【解决方案4】:

          如果有人遇到此问题:我在带有设计库应用栏的 4.45.0 手机上发生了这种情况。尝试了上述解决方案无济于事。起作用的是将我的片段的托管活动更改为LinearLayout,从而解决了问题。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2016-01-30
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-12-17
            • 1970-01-01
            • 1970-01-01
            • 2015-01-17
            相关资源
            最近更新 更多