gpt4 book ai didi

Android 首选项重叠工具栏

转载 作者:太空狗 更新时间:2023-10-29 14:51:04 25 4
gpt4 key购买 nike

我有一个偏好的安卓应用 enter image description here

如您所见,首选项与工具栏重叠。这是我的主要 fragment xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />


<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

其中包含一个新的 xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include
layout="@layout/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_partial_secure" />

</android.support.design.widget.CoordinatorLayout>

最后是 content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.gilca.ebspma.MainActivity">

<TextView
android:id="@+id/location"
android:paddingTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

我的 xml 偏好是这个

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<PreferenceCategory
android:summary="Username and password information"
android:title="Informações de Login">
<EditTextPreference
android:key="username"
android:summary="Introduzir username"
android:title="Username" />
<EditTextPreference
android:key="password"
android:summary="Introduzir password"
android:title="Password" />
</PreferenceCategory>
<PreferenceCategory
android:summary="sessao"
android:title="Definições">
<Preference
android:key="@string/myCoolButton"
android:summary="Mude aqui"
android:title="Mudar a password na BD" />
<CheckBoxPreference
android:key="checkBox"
android:summary="On/Off"
android:title="Manter Sessão" />
</PreferenceCategory>
</PreferenceScreen>

而这个xml是从SettingsFragment.java调用的

public class SettingsFragment extends PreferenceFragmentCompat {
SharedPreferences sharedPreferences;

@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.prefs);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
}
}

那么......为什么我会遇到这个问题,我该如何解决?

更新代码询问

 public boolean onNavigationItemSelected(MenuItem item) {
Fragment fragment = null;
Class fragmentClass = null;
int id = item.getItemId();
if (id == R.id.nav_home) {
fragmentClass = HomeFragment.class;
} else if (id == R.id.nav_req) {


} else if (id == R.id.nav_ver) {

} else if (id == R.id.nav_atividades) {
fragmentClass = AtividadesFragment.class;
} else if (id == R.id.nav_training) {
fragmentClass = TrainingFragment.class;
} else if (id == R.id.nav_settings) {
fragmentClass = SettingsFragment.class;
}
else if (id == R.id.nav_about) {
}
else if (id == R.id.nav_sair) {
session.logOut();
System.exit(0);
}
try{
assert fragmentClass != null;
fragment = (Fragment) fragmentClass.newInstance();
}catch (Exception e) {
e.printStackTrace();
}

FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content, fragment).commit();

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

最佳答案

尝试将 main.xml 中的“内容”框架布局对齐到“app_bar”下方。

<include
android:id="@+id/app_bar"
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />


<FrameLayout
android:id="@+id/content"
android:layout_below="@id/app_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

关于Android 首选项重叠工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35280441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com