Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何设置选定文本框的Android WebView背景_Android_Webkit - Fatal编程技术网

如何设置选定文本框的Android WebView背景

如何设置选定文本框的Android WebView背景,android,webkit,Android,Webkit,我在安卓WebView的HTML页面上找到了一个输入标签。我希望背景是透明的。它是透明的(通过背景色:透明的),直到用户选择它(给它焦点,输入数据)。然后背景是白色的 我在textbox和textbox:focus上尝试了background color,我也尝试了-webkit外观:none。这些都不起作用 有人搞错了吗?我可能错了,但这实际上看起来像是android.webkit包代码中的一个bug。 似乎WebView使用android.webkit.TextDialog类来表示输入框,即

我在安卓
WebView
的HTML页面上找到了一个输入标签。我希望背景是透明的。它是透明的(通过
背景色:透明的
),直到用户选择它(给它焦点,输入数据)。然后背景是白色的

我在
textbox
textbox:focus
上尝试了
background color
,我也尝试了
-webkit外观:none
。这些都不起作用


有人搞错了吗?

我可能错了,但这实际上看起来像是android.webkit包代码中的一个bug。 似乎
WebView
使用
android.webkit.TextDialog
类来表示输入框,即使在呈现的HTML中也是如此

然而,该代码隐藏了webkit在android文本小部件中的呈现。请注意LayerDrawable变量层、对setBackgroundDrawable()的调用以及LayerDrawable中的两个层,其中底部的层设置为始终为白色

如您所见,WebCore渲染的文本隐藏在白色背景后面。评论甚至明确指出了这一点

当然,WebView.java中的TextDialog变量mTextEntry在文本框被聚焦之前不会被聚焦,因此在此之前不会隐藏webkit正在呈现的内容

/**
 * Create a new TextDialog.
 * @param   context The Context for this TextDialog.
 * @param   webView The WebView that created this.
 */
/* package */ TextDialog(Context context, WebView webView) {
    super(context);
    mWebView = webView;
    ShapeDrawable background = new ShapeDrawable(new RectShape());
    Paint shapePaint = background.getPaint();
    shapePaint.setStyle(Paint.Style.STROKE);
    ColorDrawable color = new ColorDrawable(Color.WHITE);
    Drawable[] array = new Drawable[2];
    array[0] = color;
    array[1] = background;
    LayerDrawable layers = new LayerDrawable(array);
    // Hide WebCore's text behind this and allow the WebView
    // to draw its own focusring.
    setBackgroundDrawable(layers);
    // Align the text better with the text behind it, so moving
    // off of the textfield will not appear to move the text.
    setPadding(3, 2, 0, 0);
    mMaxLength = -1;
    // Turn on subpixel text, and turn off kerning, so it better matches
    // the text in webkit.
    TextPaint paint = getPaint();
    int flags = paint.getFlags() | Paint.SUBPIXEL_TEXT_FLAG |
            Paint.ANTI_ALIAS_FLAG & ~Paint.DEV_KERN_TEXT_FLAG;
    paint.setFlags(flags);
    // Set the text color to black, regardless of the theme.  This ensures
    // that other applications that use embedded WebViews will properly
    // display the text in textfields.
    setTextColor(Color.BLACK);
    setImeOptions(EditorInfo.IME_ACTION_NONE);
 }

git中的问题。

这似乎已在Android 2.1中修复。