我正在尝试通过典型方法更改标题栏的视图:
@OverrIDepublic 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); ...}
但是此代码由于某些原因无法正常工作.怎么了?
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);
片段,但是我有一个错误:
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(…);
解决方法:
您正在膨胀一个全新的视图,并尝试通过使用以下代码在该新膨胀的视图中找到progressbar / textvIEw:
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);
尝试将其更改为此
Progressbar progressbar = (Progressbar)window.findVIEwByID(R.ID.Title_progress);TextVIEw Title_Text = (TextVIEw)window.findVIEwByID(R.ID.Title_text);
总结 以上是内存溢出为你收集整理的如何自定义onCreateView片段中的android标题栏全部内容,希望文章能够帮你解决如何自定义onCreateView片段中的android标题栏所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)