Android开发中的常见问题汇总
这些都是平时收集的一系列常见问题,希望对大家有所帮助
一、TextView 实现部分文字颜色改变 超链接样式
String html = "*注册代表同意《" + "<font color=#1FACFE><a >XXXX服务协议</a></font>" + "》";
tv_deal.setText(Html.fromHtml(html));tv_deal.setMovementMethod(LinkMovementMethod.getInstance());
二、android webview 适配html页面
//适配手机屏幕
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
三、android 调用ZXing包实现二维码预览框图片有拉伸
问题: 调用zxing包实现二维码扫码功能,预览框的图片有拉伸 分析 :zxing默认是横屏 ,而我们的需求是竖屏,所以展示有偏差 解决:CameraConfigurationManager 类 initFromCameraParameters方法替换成下面的这个
void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); previewFormat = parameters.getPreviewFormat(); previewFormatString = parameters.get("preview-format"); Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); screenResolution = new Point(display.getWidth(), display.getHeight()); Log.d(TAG, "Screen resolution: " + screenResolution); Point screenResolutionForCamera = new Point(); screenResolutionForCamera.x = screenResolution.x; screenResolutionForCamera.y = screenResolution.y; // preview size is always something like 480*320, other 320*480 if (screenResolution.x < screenResolution.y) { screenResolutionForCamera.x = screenResolution.y; screenResolutionForCamera.y = screenResolution.x; } cameraResolution = getCameraResolution(parameters, screenResolutionForCamera); Log.d(TAG, "Camera resolution: " + screenResolution); }
四、fragment 嵌套fragment
fragment嵌套里面不能用再用getActivity().getFragmentManager()要用getChildFragmentManager()
五、 listView下拉时,顶部会有一条渐变的线 解决办法是:
Android:overScrollMode="never" 或者 listView.setOverScrollMode(View.OVER_SCROLL_NEVER);
去掉点击item效果(橙黄色) android:listSelector="@android:color/transparent"
六、Android 应用隐藏标题栏和状态栏
网上找的资源: 第一种方法:在onCreate中加了如下代码
// 不显示标题栏 this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// 不显示状态栏 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
第二种方法:在清单(AndroidManifest.xml)对应的activity中添加如下代码
// 不显示标题栏 Android:theme="@android:style/Theme.NoTitleBar"
// 不显示状态栏 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|