如何在碎片定制的Android标题栏onCreateView [英] How to customize android title bar in fragments onCreateView
本文介绍了如何在碎片定制的Android标题栏onCreateView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过典型的方法来改变标题栏的看法:
I am trying to change the view of titlebar by typical approach:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle args) {
...
Window window = getActivity().getWindow();
window.requestFeature(Window.FEATURE_CUSTOM_TITLE);
window.setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.brand_update_layout);
ProgressBar progressBar = (ProgressBar) inflater.inflate(R.layout.brand_update_layout, group, false)
.findViewById(R.id.title_progress);
TextView title_Text = (TextView) inflater.inflate(R.layout.brand_update_layout, group, false)
.findViewById(R.id.title_text);
title_Text.setText(Html.fromHtml("..."));
progressBar.setVisibility(View.VISIBLE);
...
}
但是,这code并不能在一些工作的原因。什么错?
But this code does not work on some reason. Whats wrong?
UPD。 好吧,我宣布
Window window = getWindow();
window.requestFeature(Window.FEATURE_CUSTOM_TITLE);
window.setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.brand_update_layout);
在活动以及
ProgressBar progressBar = (ProgressBar)getActivity().getWindow().findViewById(R.id.title_progress);
TextView title_Text = (TextView)getActivity().getWindow().findViewById(R.id.title_text);
title_Text.setText(...);
progressBar.setVisibility(View.VISIBLE);
在片段,但我有一个错误:
in fragment, however I have an error:
ERROR/AndroidRuntime(12213): java.lang.NullPointerException
at com.quto.ru.CarListFragment.onCreateView(CarListFragment.java:188)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:837)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1041)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:616)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1359)
在字符串 title_Text.setText(...);
推荐答案
正在膨胀了一个全新的观点,并尝试使用该code找到进度/ TextView的在新膨胀的看法:
You are inflating a whole new view and trying to find the progressbar / textview in that newly inflated view by using this code:
ProgressBar progressBar = (ProgressBar) inflater.inflate(R.layout.brand_update_layout, group, false).findViewById(R.id.title_progress);
TextView title_Text = (TextView) inflater.inflate(R.layout.brand_update_layout, group, false).findViewById(R.id.title_text);
试着将其更改为这个
Try changing it to this
ProgressBar progressBar = (ProgressBar)window.findViewById(R.id.title_progress);
TextView title_Text = (TextView)window.findViewById(R.id.title_text);
这篇关于如何在碎片定制的Android标题栏onCreateView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文