在我的應用中更改方向後,操作欄中的標題將從在導航器抽屜中選擇的片段的標題更改爲應用的標題。修復導航抽屜方向變化時的標題更改?
的Navigation drawer example app保留它的標題與方向的變化,因爲它的片段是主要活動的一個子類,並擁有這行代碼
getActivity().setTitle(planet);
現在我有點新手,所以我不知道如何保留標題,並執行代碼,你們可以幫忙嗎?
萬一任何你想看到的,這裏是爲PlanetFragment
public static class PlanetFragment extends Fragment {
public static final String ARG_PLANET_NUMBER = "planet_number";
public PlanetFragment() {
// Empty constructor required for fragment subclasses
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_planet, container, false);
int i = getArguments().getInt(ARG_PLANET_NUMBER);
String planet = getResources().getStringArray(R.array.planets_array)[i];
int imageId = getResources().getIdentifier(planet.toLowerCase(Locale.getDefault()),
"drawable", getActivity().getPackageName());
((ImageView) rootView.findViewById(R.id.image)).setImageResource(imageId);
getActivity().setTitle(planet);
return rootView;
}
}
它應該是'getActivity()。setTitle()' –