Android studio:膨胀操作栏和ViewGroup参数
我有以下代码:Android studio:膨胀操作栏和ViewGroup参数,android,layout-inflater,android-viewgroup,Android,Layout Inflater,Android Viewgroup,我有以下代码: setContentView(R.layout.activity_main); ActionBar mActionBar = getActionBar(); if (mActionBar != null) { mActionBar.setDisplayShowHomeEnabled(false); mActionBar.setDisplayShowTitleEnabled(false); } LayoutInflater mInflater = LayoutIn
setContentView(R.layout.activity_main);
ActionBar mActionBar = getActionBar();
if (mActionBar != null) {
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
}
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.action_bar_search, null,false);
关于null(充气的第二个参数)我得到:避免将null作为视图根传递(需要解析充气布局的根元素上的布局参数)。我读到传递null是可以的,但我承认我喜欢保持代码尽可能干净
膨胀片段时,我有容器,但我没有找到要传递的内容以避免此警告
请指教
谢谢在哪里添加“mCustomView”视图?您可以传递'mCustomView'的父视图,它将自动添加到其父视图。这样,您将保留“R.layout.action\u bar\u search”layoutparams选项。您的意思是在哪里添加“mCustomView”?在我贴的代码里。