每当我使用操作栏显示一个新片段时,无论是首选项片段还是自定义片段,背景都是透明且可单击的。我不能简单地将背景颜色设置为某种颜色,因为用户仍然可以单击片段。我认为这是问题所在,但不确定。
@Override
public boolean onOptionsItemSelected(MenuItem item) {//Present list of options on action bar touch.
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (id)
{
case R.id.action_settings:
{
getFragmentManager().beginTransaction().replace(android.R.id.content, new PrefsFragment()).addToBackStack(null).commit();
inSettings = true;
break;
}
case R.id.probabiliy:
{
getFragmentManager().beginTransaction().replace(android.R.id.content, new probabilityFragment()).addToBackStack(null).commit();
inSettings = true;
break;
}
}
return super.onOptionsItemSelected(item);
}
根据您的喜好创建一个活动,并为您的自定义片段创建一个活动,除非该片段用于您的主要活动。这样您就不会有这个问题。
片段是可以放在活动中的应用程序用户界面或行为的一部分。它不是不透明的。活动是不透明的。将活动视为虚拟窗口,将片段视为活动中的超级小部件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句