NavigationDrawerから起動するPreferenceFragmentを使用しています。 preferenceFragmentでは、ツールバーを表示します。すべてがうまく見えますが、戻ってくるにはツールバーの矢印を押しても機能しません。ログにはこれを見ることができます:NavigationDrawerのPreferenceFragmentでツールバーの矢印が機能しない
D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
しかし何もしないでください。戻ってくる唯一の方法は、デバイスのボタンを押し戻すことです。
何か助けになるでしょう。
これは私のコードです: PreferenceFragment:
public class AnPreferenceActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pref_with_actionbar);
getFragmentManager().beginTransaction()
.replace(R.id.content_frame, new SettingsPreference())
.commit();
}
public static class SettingsPreference extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
Toolbar toolbar = (Toolbar) getActivity().findViewById(R.id.toolbar);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
}
}
}
レイアウトのxml:
setHasOptionsMenu(true);
:あなたのフラグメントのonCreate()
で
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:navigationContentDescription="@string/abc_action_bar_up_description"
app:navigationIcon="?attr/homeAsUpIndicator"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="@string/action_settings" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/appbar" />
</RelativeLayout>
メニュー項目でバックプレスを処理しましたか? onOptionMenuを押すとandroid.R.id.homeする必要があります** backPressed()** – Amir
こんにちはアミール、私はあなたを理解しているかどうかはわかりません。私はアンドロイドの何か新しいです。私にこれのコードを少し見せてもらえますか? –