最近在使用webview做页面开发,项目上要求webview在获取到焦点的时候需要有边框线,于是添加上了webview的选中效果,但是出现了网页中的内容压选中框的情况。之后给webview添加padding也不能解决这个问题,从网上搜索后发现,webview设置padding是不会起作用的,这个是webview的一个bug。但是问题还是地解决的,于是想了如下的webview选中的替代方案:

  1. webview设置背景色为透明色
  2. 在webview下方放一个LinearLayout里面有个ImageView,大小刚好比webview大出一个边框
  3. 当webview获取到焦点的时候,显示有边框的ImageView,当webview失去焦点的时候,显示正常的无边框的ImageView。

下面贴出代码:

1.xml文件配置(LinearLayout在webview下面并且比其大4dp)

<LinearLayout
android:id="@+id/web_linerlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="2dp"
android:layout_alignParentBottom="true"
android:layout_below="@+id/title_Relay"
android:layout_toRightOf="@id/btn"
android:layout_marginTop="5dp"
android:layout_marginRight="8dp"
android:background="@color/3C123456"
android:padding="0dp">
</LinearLayout>
<WebView
android:id="@+id/web_WebView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="6dp"
android:layout_alignParentBottom="true"
android:layout_below="@+id/title_Relay"
android:layout_toRightOf="@id/btn"
android:layout_marginTop="9dp"
android:layout_marginRight="11dp"
android:layout_marginBottom="4dp"
android:layerType="software"
android:hardwareAccelerated="true">
</WebView>

2.JAVA代码

final LinearLayout linearlayout = (LinearLayout)findViewById(R.id.web_linerlayout);
final ImageView imageView = new ImageView(MainActivity.this);
imageView.setImageResource(R.drawable.webview_select);
LayoutParams layoutParams = new LayoutParams(linearlayout.getLayoutParams().width, linearlayout.getLayoutParams().height);
imageView.setLayoutParams(layoutParams);
linearlayout.addView(imageView); WebView shopWeb = (WebView) findViewById(R.id.web_WebView);
shopWeb.setOnFocusChangeListener(new View.OnFocusChangeListener()
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
linearlayout.removeView(imageView);
}else{
linearlayout.addView(imageView);
}
}
});

android webview内容压线问题解决方法的更多相关文章

  1. 【转】 Android WebView内容宽度自适应

    我们平常在项目中有可能会遇到网页的内容是通过json数据传递到app上面用WebView来显示的,这时候我们通常都要调整内容的总宽度不超过父容器的宽度,这样子用户可以不用左右滑动就可以看到全部的内容. ...

  2. Android 5.x 权限问题解决方法

    android 5.x开始,引入了非常严格的selinux权限管理机制,我们经常会遇到因为selinux权限问题造成的各种avc denied困扰.  本文结合具体案例,讲解如何根据log来快速解决9 ...

  3. 关于Android WebView内容不同屏幕兼容处理

    最近团队里项目开发APP时,其中有个界面要用到WebView来显示,而不用原生的控件. 开发这个界面的时候遇到一个问题,就是Android的碎片化导致有众多屏幕分辨率,不同分辨率的屏幕对这个界面Web ...

  4. android webview内存泄露解决方法

    完整的activity的onDestroy()方法:@Override protected void onDestroy() { if( mWebView!=null) { // 如果先调用destr ...

  5. Android webview通过http get下载文件下载两次的问题及解决方法

    一.现象 一般通过Android webview进行下载文件的方法是 1.重写DownloadListener的onDownloadStart方法,在onDownloadStart方法中弹出对话框提示 ...

  6. Android webview 写入cookie的解决方法以及一些属性设置

    原文地址:https://www.2cto.com/kf/201703/616868.html Android webview 写入cookie的解决方法以及一些属性设置,webview怎么设置写入C ...

  7. Android WebView 不支持 H5 input type="file" 解决方法

    最近因为赶项目进度,因此将本来要用原生控件实现的界面,自己做了H5并嵌入webview中.发现点击H5中 标签 不能打开android资源管理器. 通过网络搜索发现是因为 android webvie ...

  8. Android WebView 调试方法

    调试Android WebView中的h5页面,通常就是通过alert和抓包工具来定位问题,效率低且无法直接调试样式或打断点,可谓是事倍功半.本文介绍一下我在项目中使用的新方法,能够通过chrome的 ...

  9. 安装Android SDK Manager的“Failed to fetch refused”问题解决方法

    安装Android SDK Manager的"Failed to fetch refused"问题解决方法 一见 2014/11/11 问题现象: 步骤一:修改hosts文件(wi ...

随机推荐

  1. 将一个字符串映射为一个Delphi页面控件属性名(通过FindComponent和GetPropInfo找到这个控件指针)

    uses TypInfo; function TForm1.SetControlProp(ComStr, value: string): boolean; var ComName, ComProp: ...

  2. 《ArcGIS Engine+C#实例开发教程》第一讲桌面GIS应用程序框架的建立

    原文:<ArcGIS Engine+C#实例开发教程>第一讲桌面GIS应用程序框架的建立 摘要:本讲主要是使用MapControl.PageLayoutControl.ToolbarCon ...

  3. ptr_fun学习笔记

    ptr_fun是将一个普通的函数适配成一个functor,添加上argument type和result type等类型, 其实现如下(例子里面是binary_function,unary_funct ...

  4. Azure Backup 简介

    ViswanathTata云 +Enterprise 项目经理 AzureBackup是 Azure恢复服务的一部分,在安全高效的环境中对上传到 Azure的数据提供简单可靠的管理和保护.Azur ...

  5. WCF大数据量传输配置

    WCF传输数据量的能力受到许多因素的制约,如果程序中出现因需要传输的数据量较大而导致调用WCF服务失败的问题,应注意以下配置: 1.MaxReceivedMessageSize:获取或设置配置了此绑定 ...

  6. 处理Selection对象和Range对象——Word VBA中重要的两个对象

    处理Selection对象和Range对象——Word VBA中重要的两个对象 Word 开发人员参考Selection 对象代表窗口或窗格中的当前所选内容.所选内容代表文档中选定(或突出显示)的区域 ...

  7. C#使用SOAP调用Web Service

    程序代码 using System;using System.IO;using System.Net;using System.Text; namespace ConsoleApplication1{ ...

  8. 使用Bugfree不应有的坏习惯

    Bugfree是一款优秀的bug管理和追踪工具,因此受到不少公司的青睐.但实际的工作中,我发现不少开发或是测试的同事有一些不好的使用习惯,使得我们对Bugfree的利用不够高效.我下面列出使用Bugf ...

  9. POJ2236 Wireless Network 并查集

    水题 #include<cstdio> #include<cstring> #include<queue> #include<set> #include ...

  10. [POJ3684]Physics Experiment

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1363   Accepted: 476   Special Judge ...