Ich habe die offizielle Android-Dokumentation auf how to create a settings activity using a fragment gefolgt, aber ich habe dieses Ergebnis:App bar überlappende Einstellungen in Android Aktivität
habe ich versucht, einen oberen Rand auf die Einstellungen Inhalte einstellen, sondern dass didn‘ Wenn Sie das Ergebnis ändern, werden die Einstellungen immer noch unterhalb der App-Leiste angezeigt, wie Sie auf dem Bild sehen können.
So sind dies die relevanten Teile meines Codes:
Meine Einstellungen Aktivität
public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Display the settings fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
}
Nichts Besonderes hier, ich habe gerade die Layout-Datei laden und das Fragment mit der Liste der Einstellungen einfügen .
Die Einstellungen Fragment
public class SettingsFragment extends PreferenceFragment {
public SettingsFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
}
Wieder nichts Besonderes, lade ich einfach die Einstellungen aus ihrer XML-Datei.
Die Einstellungen Aktivität Layout
<?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="com.mydomain.myapp.SettingsActivity">
<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_settings" />
</android.support.design.widget.CoordinatorLayout>
Die Einstellungen Aktivität Inhalt Layout
<?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.mydomain.myapp.SettingsActivity"
tools:showIn="@layout/activity_settings">
</RelativeLayout>
Das ist für jetzt leer ist, wie ich alles Laden aus der XML-Einstellungen sowieso Datei.
Wie kann ich sicherstellen, dass der Inhalt meiner Einstellungsaktivität direkt unter der App-Leiste der Aktivität angezeigt wird?
Perfekt, danke :) – user1301428