【Android】Android部分问题记录
2024-09-03 12:13:18
1.EditText不显示光标
开发的时候遇到有部分手机,小米系列以及华为部分手机不显示光标。
设置EditText属性
android:textCursorDrawable="@null"
android:cursorVisible="true"
可参考,http://stackoverflow.com/questions/15093758/edittext-cursor-is-invisible-in-android-4-0第一个回答。
附上我自己封装的一个方法
private final static String TAG = "EditTextCompat"; /**
* 设置光标可见 <br/>
* 此处为了解决部分手机(如小米、华为)无法显示光标的问题,由于编译环境为2.3,导致部分函数无法调用,此处使用反射调用<br/>
*/
public static void setCursorVisible(EditText editText, Context context) {
editText.setCursorVisible(true);
// sdk
// 对应关系表,见http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
if (android.os.Build.VERSION.SDK_INT >= 12) {// Android 3.1.x API12
// HONEYCOMB_MR1
String filedNameString = "mCursorDrawableRes";
// mCursorDrawableRes
Class<? extends EditText> editTextClass = editText.getClass();
Class<? extends TextView> textViewClass = null;
if (editTextClass != null) {
textViewClass = (Class<? extends TextView>) editTextClass
.getSuperclass();
}
if (textViewClass != null) {
Field mCursorDrawableField = null;
try {
mCursorDrawableField = textViewClass
.getDeclaredField(filedNameString);
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
Log.i(TAG, "NoSuchFieldException");
e.printStackTrace();
}
if (mCursorDrawableField != null) {
mCursorDrawableField.setAccessible(true);
try {
mCursorDrawableField.set(editText, 0); } catch (IllegalArgumentException e) {
Log.i(TAG, "IllegalArgumentException");
e.printStackTrace();
} catch (NotFoundException e) {
Log.i(TAG, "NotFoundException");
e.printStackTrace();
} catch (IllegalAccessException e) {
Log.i(TAG, "IllegalAccessException");
e.printStackTrace();
}
} }
}
}
}
2.AutoCompleteTextView在部分手机(如联想a860e)显示黑条。
见图
解决方案:在themes.xml设置一个主题,设置它的android:dropDownListViewStyle属性。
<style name="search_theme" parent="android:style/Theme.NoTitleBar">
<item name="android:dropDownListViewStyle">@style/widget_dropdownlistview</item>
</style>
在styles.xml中定义下面字段。
<style name="widget_dropdownlistview" parent="android:style/Widget.Holo.ListView.DropDown">
<item name="android:scrollbars">none</item>
<item name="android:divider">@color/white</item>
</style>
对需要用到AutoCompleteTextView的Activity设置主题(AndroidManifest.xml中设置)。
然后样式就OK了。
如图
可参考http://www.apkbus.com/android-126131-1-1.html
3.Dialog在部分手机上显示黑条
设置
<item name="android:windowContentOverlay">@null</item>
可参考。http://www.cnblogs.com/kaima/archive/2011/07/29/2121457.html
最新文章
- leetcode-99 Recover_Binary_Search_Tree
- python杂记-3(购买商品)
- css样式编辑
- 【Linux远程管理】RDP协议远程管理
- 用C#来查看电脑硬件和系统信息
- sql语句读取所有父子标签
- Linux下javaweb
- Extjs4中的常用组件:Grid、Tree和Form
- web前端概念巩固(一)
- 在Ubuntu16.04上部署LXC容器管理系统的相关步骤
- weblogic找不到数据源
- numpy+plot初试
- 2018-2019-2 网络对抗技术 20165228 Exp6 信息搜集与漏洞扫描
- Mysql线程池系列一:什么是线程池和连接池( thread_pool 和 connection_pool)
- 01: RestfulAPI与HTTP
- docker容器中搭建kafka集群环境
- C++运算符重载三种形式(成员函数,友元函数,普通函数)详解
- Java 运行时数据区域
- BZOJ2118:墨墨的等式(最短路)
- 温习js中对象的继承