将自定义主题应用于PreferenceFragment中的ActionBar [英] Applying custom theme to ActionBar in PreferenceFragment

查看:148
本文介绍了将自定义主题应用于PreferenceFragment中的ActionBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将自定义主题应用于PreferenceFragment中的ActionBar.以下是场景:

I am trying to apply custom theme to ActionBar in PreferenceFragment. Following is the scenerio:

我的课程扩展了PreferenceFragment,其中我将资源添加的首选项添加为:

My class extends PreferenceFragment in which I am adding preferences from resouces as:

addPreferenceFromResource (R.xml.myPrefs);

我也写过:

ActionBar a = getActivity ().getActionBar ();
bar.setNavigationMode (ActionBar.NAVIGATION_MODE_TABS);

现在,我想将在styles.xml中定义的我自己的主题应用于此操作栏.当前,操作栏的高度小于选项卡视图的高度,因此该视图将被裁剪.

Now I want to apply my own theme that I defined in styles.xml to this action bar. Currently, the height of action bar is smaller that the tab view due to which the view is getting cropped.

我尝试搜索,但是找不到解决我问题的方法.

I tried searching but couldn't find a solution to my problem.

  1. "设置片段的主题"
  2. https://groups.google.com/forum/# !topic/android-developers/GX_gOAN2nmM
  1. "Set theme for a Fragment"
  2. https://groups.google.com/forum/#!topic/android-developers/GX_gOAN2nmM

从上面的1.和2.链接中,我了解到:

From 1. and 2. links above, I learnt that:

final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(),R.style.yourCustomTheme);

// clone the inflater using the ContextThemeWrapper
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);

// inflate the layout using the cloned inflater, not default inflater
return localInflater.inflate(R.layout.yourLayout, container, false);

但这也不起作用.

我们非常感谢您的帮助.

Any help is highly appreciated.

推荐答案

最终找到了解决我问题的方法.当我纠结于复杂的事物时,似乎有一个简单的解决方案.

Finally found solutions to my problem. Seems like there was a simple solution while I tangled myself into complex things.

我刚刚在我的PreferenceFragment类的onCreate ()中添加了以下代码...一切都变得完美了!

I just added the following line to the onCreate () of my PreferenceFragment class... and everything became perfect!

getActivity ().setTheme (R.style.myCustomTheme);

希望它可以帮助可能遇到相同问题的人! :)

Hope it helps someone who might face the same problem! :)

这篇关于将自定义主题应用于PreferenceFragment中的ActionBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆