1
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
안녕 아미르, 내가 당신을 이해하는 경우 확실하지. 나는 안드로이드에 새로운 뭔가가있어. 이 코드를 제게 보여 주시겠습니까? –