Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用setCustomView的自定义操作栏-是否充气?_Android_Android Actionbar - Fatal编程技术网

Android 使用setCustomView的自定义操作栏-是否充气?

Android 使用setCustomView的自定义操作栏-是否充气?,android,android-actionbar,Android,Android Actionbar,出于某种原因,下面的两个代码块都可以工作,但它们显示的结果略有不同。有人能解释一下区别吗 第1版: View customView = getLayoutInflater().inflate(R.layout.custom_test, null); actionBar.setCustomView ( customView ); actionBar.setDisplayOptions ( ActionBar.DISPLAY_SHOW_CUSTOM ); 第2版: actionBa

出于某种原因,下面的两个代码块都可以工作,但它们显示的结果略有不同。有人能解释一下区别吗

第1版:

View customView = getLayoutInflater().inflate(R.layout.custom_test, null);
    actionBar.setCustomView ( customView );
    actionBar.setDisplayOptions ( ActionBar.DISPLAY_SHOW_CUSTOM );
第2版:

actionBar.setCustomView ( R.layout.custom_test );
    actionBar.setDisplayOptions ( ActionBar.DISPLAY_SHOW_CUSTOM );

在第一个选项中,将父根上的视图设置为null,这意味着在将其设置为actionBar视图后,它不会继承其根属性(android本机上设置的填充/边距和其他样式参数),在第二个版本中,您没有指定null父级,因此它继承自本机actionBar根样式