android-为什么当用作ActionBar自定义视图时,此EditText的宽度奇怪?

android-为什么当用作ActionBar自定义视图时,此EditText的宽度奇怪?,第1张

概述我在ActionBar中使用EditText作为自定义视图.LayoutInflateradbInflater=LayoutInflater.from(getActivity());ViewetSearchView=adbInflater.inflate(R.layout.edit_text_search,null);etSearch=(EditText)etSearchView.findViewById(R.id.search_edit_text);//ot

我在Actionbar中使用EditText作为自定义视图.

LayoutInflater adbInflater = LayoutInflater.from(getActivity());VIEw etSearchVIEw = adbInflater.inflate(R.layout.edit_text_search, null);etSearch = (EditText) etSearchVIEw.findVIEwByID(R.ID.search_edit_text);//other etSearch propertIEs are setMainActivity.ab.setCustomVIEw(etSearch);

edit_text_search.xml:

<EditText xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:ID="@+ID/search_edit_text"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:inputType="text|textautoCorrect"    androID:hint="@string/keywords"    androID:imeOptions="actionSearch"    androID:hapticFeedbackEnabled="true"    androID:singleline="true"    androID:textCursorDrawable="@drawable/cursor"    androID:textcolor="@androID:color/white"></EditText>

我有这种行为…(不想要的)

另一方面,当EditText的宽度和高度在代码中用

LayoutParams layoutParams = new LayoutParams(    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);etSearch.setLayoutParams(layoutParams);

并从xml文件中删除androID:layout_wIDth =“ match_parent”和androID:layout_height =“ wrap_content”,我有这个(期望的)外观…

在相同的宽度和高度下怎么办?

这是因为,在代码中,它们暗示要添加换行布局吗?

解决方法:

How is this possible, with the same wIDth and height?

EditText中使用的布局参数与将视图添加到Actionbar时应用的布局参数不同.每个VIEwGroup都有一个实现自己的ViewGroup.LayoutParams的嵌套类.

默认情况下为ActionBar.LayoutParams are set to WRAP_CONTENT and MATCH_PARENT,因此当您不通过Actionbar.setCustomVIEw(VIEw,LayoutParams)来应用自己的时,the ActionBar falls back on the default.

总结

以上是内存溢出为你收集整理的android-为什么当用作ActionBar自定义视图时,此EditText的宽度奇怪?全部内容,希望文章能够帮你解决android-为什么当用作ActionBar自定义视图时,此EditText的宽度奇怪?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1211377.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-04
下一篇2022-06-04

发表评论

登录后才能评论

评论列表(0条)

    保存