简体   繁体   English

为什么差异LayoutInflater会导致差异SearchView图标

[英]Why difference LayoutInflater cause difference SearchView Icon

Hello every Android geek, i has using LayoutInflater to customer My Android ActionBar. 您好,每位Android极客,我都使用LayoutInflater来吸引我的Android ActionBar。

but i found that difference LayoutInflater will cause generate difference SearchView Icon 但我发现差异LayoutInflater会导致生成差异SearchView图标

This is my Difference LayoutInflater and capture image 这是我的区别LayoutInflater和捕获图像

LayoutInflater mInflater1 =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//You can change mInflater1 =LayoutInflater.from(this); is a same result

LayoutInflater mInflater2 =LayoutInflater.from(getApplicationContext());

这是mInflater1结果

这是mInflater2结果

My Question is Why difference LayoutInflater cause difference SearchView Icon ? 我的问题是,为什么LayoutInflater差异会导致SearchView Icon差异?

The problem is that in the second example (which I believe correlates to the first picture), you are using an Application Context to inflate Views instead of an Activity Context. 问题在于,在第二个示例中(我认为这与第一张图片相关),您正在使用应用程序上下文来填充视图而不是活动上下文。

The framework does a lot of work to ensure that an Activity's Context is correctly configured with the correct screen density, theme, and other such information. 该框架做了很多工作,以确保使用正确的屏幕密度,主题和其他此类信息正确配置“活动的上下文”。 An Application is not expected to ever need to worry about displaying content, so it is not configured to do so. 预计应用程序永远不必担心显示内容,因此无需进行配置。

Do not use an Application context to inflate Views or obtain resources. 不要使用应用程序上下文来膨胀视图或获取资源。 Use an Activity context. 使用活动上下文。

Well its that the context determines from where(theme) the icons are created. 很好的是,上下文决定了从哪里创建主题。 I guess your OS and the app has different themes Read more here http://developer.android.com/reference/android/view/LayoutInflater.html 我想您的操作系统和应用程序具有不同的主题,请点击此处了解更多信息http://developer.android.com/reference/android/view/LayoutInflater.html

The Context in which this LayoutInflater will create its Views; most importantly, this supplies the theme from which the default values for their attributes are retrieved.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM