Как добавить предпочтения XML внутри макета во фрагменте - PullRequest
0 голосов
/ 28 августа 2018

Я хочу взглянуть на активность профиля, чтобы отобразить имя пользователя и изображение, а ниже - экран настроек. Я использовал PreferenceFragmentCompat в андроид студии, но он не работает вообще. Я хочу объединить мои видовые виджеты с экраном настроек.

Вот мой фрагмент настроек:

public  class FragmentSettings extends PreferenceFragmentCompat{

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.preference_settings);
}


@Override
public View onCreateView(LayoutInflater layoutInflater , @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){
    return layoutInflater.inflate(R.layout.fragment_settings,container,false);
}

}

Вот мой preference_settings.xml

<android.support.v7.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">

<android.support.v7.preference.PreferenceCategory
    android:title="Category 1">

    <android.support.v7.preference.SwitchPreferenceCompat
        android:key="key1"
        android:title="Switch Preference"
        android:summary="Switch Summary"
        android:defaultValue="true" />

    <android.support.v7.preference.EditTextPreference
        android:key="key2"
        android:title="EditText Preference"
        android:summary="EditText Summary"
        android:dialogMessage="Dialog Message"
        android:defaultValue="Default value" />
    <android.support.v7.preference.CheckBoxPreference
        android:key="key3"
        android:title="CheckBox Preference"
        android:summary="CheckBox Summary"
        android:defaultValue="true"/>
</android.support.v7.preference.PreferenceCategory>

а вот фрагмент-вид.xml:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="15dp"
        android:paddingBottom="15dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:src="@mipmap/user" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/imageView"
        android:textSize="25dp"
        android:textAlignment="center"
        android:text="TextView" />

    <ListView
        android:id="@+id/android:list"
        android:layout_below="@id/textView4"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

Я хочу сделать так: enter image description here

1 Ответ

0 голосов
/ 28 августа 2018

Если вы хотите поместить FragmentSettings в макет, вы можете использовать контейнер фрагментов внутри fragment_settings.xml и поместить свой FragmentSettings в него.

...