我想使用带有片段标题的自定义操作栏。但是此方法仅显示所有片段的应用程序名称。我需要在操作栏中使用适当的片段名称。
getActivity().getActionBar().setDisplayShowCustomEnabled(true);
getActivity().getActionBar().setDisplayShowTitleEnabled(false);
LayoutInflater inflator = LayoutInflater.from(getActivity());
View v = inflator.inflate(R.layout.title, null);
//if you need to customize anything else about the text, do it here.
//I'm using a custom TextView with a custom font in my layout xml so all I need to do is set title
((TextView)v.findViewById(R.id.title)).setText(getActivity().getTitle());
//assign the view to the actionbar
getActivity().getActionBar().setCustomView(v);
答案 0 :(得分:0)
您只需要定义一个方法来更新操作栏的标题,并从ever / Fragment onResume()
活动:
@Override
public void onResume() {
// For activity
setActionbarTitle("title");
// For Fragment
((ParentActivtyNAme)getActivty).setActionbarTitle("title");
}
setActionbarTitle方法:
public void setActionbarTitle(String title) {
textTitle.setText(title);
}
在操作栏中设置自定义视图时初始化textTitle
:
textTitle= ((TextView)v.findViewById(R.id.title));
希望它能帮助你ツ