Android開發(fā)之WebView輸入框提示解決辦法
做基于WebView應(yīng)用時,頁面上有一個輸入框,當輸入的文字過多時,超過輸入框的行數(shù)時,輸入框能夠滾動,這時間問題來了,輸入的提示箭頭會移動到輸入框外,如何解決這個問題呢,查找chromium源碼如下:
void LoadIfNecessary(jobject context) { if (loaded_) return; loaded_ = true; TRACE_EVENT0("browser", "HandleResources::Create"); JNIEnv* env = base::Android::AttachCurrentThread(); if (!context) context = base::android::GetApplicationContext(); left_bitmap_ = CreateSkBitmapFromJavaBitmap( Java_HandleViewResources_getLeftHandleBitmap(env, context)); right_bitmap_ = CreateSkBitmapFromJavaBitmap( Java_HandleViewResources_getRightHandleBitmap(env, context)); center_bitmap_ = CreateSkBitmapFromJavaBitmap( Java_HandleViewResources_getCenterHandleBitmap(env, context)); left_bitmap_.setImmutable(); right_bitmap_.setImmutable(); center_bitmap_.setImmutable(); drawable_horizontal_padding_ratio_ = Java_HandleViewResources_getHandleHorizontalPaddingRatio(env); }
這個函數(shù)加載這幾個圖片,在java端,
private static Bitmap getHandleBitmap(Context context, final int[] attrs) { // TODO(jdduke): Properly derive and apply theme color. TypedArray a = context.getTheme().obtainStyledAttributes(attrs); final int resId = a.getResourceId(a.getIndex(0), 0); final Resources res = a.getResources(); a.recycle(); final Bitmap.Config config = Bitmap.Config.ARGB_8888; final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = false; options.inPreferredConfig = config; Bitmap bitmap = BitmapFactory.decodeResource(res, resId, options); savePic( bitmap); if (bitmap != null) return bitmap; // If themed resource lookup fails, fall back to using the Context's // resources for attribute lookup. if (res != context.getResources()) { bitmap = BitmapFactory.decodeResource(context.getResources(), resId, options); if (bitmap != null) return bitmap; } Drawable drawable = getHandleDrawable(context, attrs); assert drawable != null; final int width = drawable.getIntrinsicWidth(); final int height = drawable.getIntrinsicHeight(); Bitmap canvasBitmap = Bitmap.createBitmap(width, height, config); Canvas canvas = new Canvas(canvasBitmap); drawable.setBounds(0, 0, width, height); drawable.draw(canvas); return canvasBitmap; }
C++中會調(diào)用java中的函數(shù)getHandleBitmap,這個函數(shù)通過 context.getTheme().obtainStyledAttributes 這個函數(shù),從jdk中加載圖片資源,顯示時,通過GetBitmap函數(shù)獲取到圖像信息,通過layer_->SetBitmap( bitmap)設(shè)置顯示的內(nèi)容,函數(shù)如下:
const SkBitmap& GetBitmap(ui::TouchHandleOrientation orientation) { DCHECK(loaded_); switch (orientation) { case ui::TouchHandleOrientation::LEFT: return left_bitmap_; case ui::TouchHandleOrientation::RIGHT: return right_bitmap_; case ui::TouchHandleOrientation::CENTER: return center_bitmap_; case ui::TouchHandleOrientation::UNDEFINED: NOTREACHED() << "Invalid touch handle orientation."; }; return center_bitmap_; }
這么分析下來,想從顯示下手解決這個問題,似乎不太可能,那只有替換圖片資源,而圖像資源是在android.jar包中,還有其他辦法嗎? 分析源碼,
public static Drawable getLeftHandleDrawable(Context context) { return getHandleDrawable(context, LEFT_HANDLE_ATTRS); } public static Drawable getCenterHandleDrawable(Context context) { return getHandleDrawable(context, CENTER_HANDLE_ATTRS); } public static Drawable getRightHandleDrawable(Context context) { return getHandleDrawable(context, RIGHT_HANDLE_ATTRS); }
有這幾個圖像id 信息,是不是可以重載呢,于是添加自己的
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="MyTheme"> <item name="android:textSelectHandleLeft">@drawable/ic_launcher</item> <item name="android:textSelectHandle">@drawable/aa</item> <item name="android:textSelectHandleRight">@drawable/ic_launcher</item> </style> </resources>
替換掉系統(tǒng)的資源,再添加android:theme="@style/MyTheme" 自己的主題風格,問題解決
相關(guān)文章
android獲取當前接入點信息判斷是ctwap還是ctnet實例代碼
這篇文章主要介紹了android獲取當前接入點信息判斷是ctwap還是ctnet的方法,大家參考使用吧2013-11-11Android中TextView實現(xiàn)分段顯示不同顏色的字符串
在做項目的時候,遇到過一行文字有兩種顏色。在菜鳥的時候直接會想到用多個TextView來實現(xiàn),所以下面這篇文章主要給大家介紹了關(guān)于Android中TextView如何實現(xiàn)分段顯示不同顏色字符串的相關(guān)資料,需要的朋友可以參考下。2017-12-12Android中ListView的item點擊沒有反應(yīng)的解決方法
這篇文章主要介紹了Android中ListView的item點擊沒有反應(yīng)的相關(guān)資料,需要的朋友可以參考下2017-10-10Android 數(shù)據(jù)存儲之 FileInputStream 工具類及FileInputStream類的使用
這篇文章主要介紹了Android 數(shù)據(jù)存儲之 FileInputStream 工具類及FileInputStream類的使用的相關(guān)資料,需要的朋友可以參考下2015-11-11android計算器實現(xiàn)兩位數(shù)的加減乘除
這篇文章主要為大家詳細介紹了android計算器實現(xiàn)兩位數(shù)的加減乘除,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-03-03Android學習筆記-保存數(shù)據(jù)到SQL數(shù)據(jù)庫中(Saving Data in SQL Databases)
這篇文章主要介紹了Android學習筆記-保存數(shù)據(jù)到SQL數(shù)據(jù)庫中的(Saving Data in SQL Databases)2014-10-10