當前位置: 首頁>>代碼示例>>Java>>正文


Java View.clearFocus方法代碼示例

本文整理匯總了Java中android.view.View.clearFocus方法的典型用法代碼示例。如果您正苦於以下問題:Java View.clearFocus方法的具體用法?Java View.clearFocus怎麽用?Java View.clearFocus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.View的用法示例。


在下文中一共展示了View.clearFocus方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createBitmapFromView

import android.view.View; //導入方法依賴的package包/類
/**
 * 從一個view創建Bitmap。
 * 注意點:繪製之前要清掉 View 的焦點,因為焦點可能會改變一個 View 的 UI 狀態。
 * 來源:https://github.com/tyrantgit/ExplosionField
 *
 * @param view  傳入一個 View,會獲取這個 View 的內容創建 Bitmap。
 * @param scale 縮放比例,對創建的 Bitmap 進行縮放,數值支持從 0 到 1。
 */
public static Bitmap createBitmapFromView(View view, float scale) {
    if (view instanceof ImageView) {
        Drawable drawable = ((ImageView) view).getDrawable();
        if (drawable != null && drawable instanceof BitmapDrawable) {
            return ((BitmapDrawable) drawable).getBitmap();
        }
    }
    view.clearFocus();
    Bitmap bitmap = createBitmapSafely((int) (view.getWidth() * scale),
            (int) (view.getHeight() * scale), Bitmap.Config.ARGB_8888, 1);
    if (bitmap != null) {
        synchronized (sCanvas) {
            Canvas canvas = sCanvas;
            canvas.setBitmap(bitmap);
            canvas.save();
            canvas.drawColor(Color.WHITE); // 防止 View 上麵有些區域空白導致最終 Bitmap 上有些區域變黑
            canvas.scale(scale, scale);
            view.draw(canvas);
            canvas.restore();
            canvas.setBitmap(null);
        }
    }
    return bitmap;
}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:33,代碼來源:QMUIDrawableHelper.java

示例2: createBitmapFromView

import android.view.View; //導入方法依賴的package包/類
public static Bitmap createBitmapFromView(View view) {
	if (view instanceof ImageView) {
		Drawable drawable = ((ImageView) view).getDrawable();
		if (drawable != null && drawable instanceof BitmapDrawable) {
			return ((BitmapDrawable) drawable).getBitmap();
		}
	}
	view.clearFocus();
	Bitmap bitmap = createBitmapSafely(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888, 1);
	if (bitmap != null) {
		synchronized (sCanvas) {
			Canvas canvas = sCanvas;
			canvas.setBitmap(bitmap);
			view.draw(canvas);
			canvas.setBitmap(null);
		}
	}
	return bitmap;
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:20,代碼來源:ExplosionField.java

示例3: dispatchTouchEvent

import android.view.View; //導入方法依賴的package包/類
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        View v = getCurrentFocus();
        if ( v instanceof EditText) {
            Rect outRect = new Rect();
            v.getGlobalVisibleRect(outRect);
            if (!outRect.contains((int)event.getRawX(), (int)event.getRawY())) {
                v.clearFocus();
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
        }
    }
    return super.dispatchTouchEvent( event );
}
 
開發者ID:Pritom14,項目名稱:Password-Storage,代碼行數:17,代碼來源:RegistrationActivity.java

示例4: clearFocus

import android.view.View; //導入方法依賴的package包/類
private void clearFocus(Activity activity) {
    View v = activity.getCurrentFocus();
    if (v != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        v.clearFocus();
    }
}
 
開發者ID:ebridfighter,項目名稱:GongXianSheng,代碼行數:9,代碼來源:PlaceOrderProductAdapter.java

示例5: onFocusChange

import android.view.View; //導入方法依賴的package包/類
@Override
public void onFocusChange(View view, boolean isFocused) {
    if (isFocused && !mCursorVisible) {
        if (mDelPressed) {
            currentFocus = view;
            mDelPressed = false;
            return;
        }
        for (final EditText editText : editTextList) {
            if (editText.length() == 0) {
                if (editText != view) {
                    editText.requestFocus();
                } else {
                    currentFocus = view;
                }
                return;
            }
        }
        if (editTextList.get(editTextList.size() - 1) != view) {
            editTextList.get(editTextList.size() - 1).requestFocus();
        } else {
            currentFocus = view;
        }
    } else if (isFocused && mCursorVisible) {
        currentFocus = view;
    } else {
        view.clearFocus();
    }
}
 
開發者ID:GoodieBag,項目名稱:Pinview,代碼行數:30,代碼來源:Pinview.java

示例6: clearViewFocus

import android.view.View; //導入方法依賴的package包/類
/**
 * 清除editText的焦點
 *
 * @param v   焦點所在View
 * @param ids 輸入框
 */
public void clearViewFocus(View v, int... ids) {
    if (null != v && null != ids && ids.length > 0) {
        for (int id : ids) {
            if (v.getId() == id) {
                v.clearFocus();
                break;
            }
        }
    }


}
 
開發者ID:zybieku,項目名稱:SoftKeyboardUtil,代碼行數:19,代碼來源:BaseActivity.java

示例7: theTimePickerIsGoneWhenEditingTheSearchField

import android.view.View; //導入方法依賴的package包/類
@Test
public void theTimePickerIsGoneWhenEditingTheSearchField() {
    SetAlarmActivity activity = Robolectric.buildActivity(SetAlarmActivity.class).create().get();
    View searchField = activity.findViewById(R.id.podcast_rss_feed);
    View timePicker = activity.findViewById(R.id.time_picker);

    searchField.requestFocus();
    assertEquals(View.GONE, timePicker.getVisibility());

    searchField.clearFocus();
    assertEquals(View.VISIBLE, timePicker.getVisibility());
}
 
開發者ID:KevinLiddle,項目名稱:crockpod,代碼行數:13,代碼來源:SetAlarmActivityTest.java

示例8: dispatchTouchEvent

import android.view.View; //導入方法依賴的package包/類
@Override public boolean dispatchTouchEvent(MotionEvent ev) {
  if (isAutoHideInputView) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
      View v = getCurrentFocus();
      if (v != null) {
        if ((v instanceof EditText)) {
          if (!AppUtils.isEventInVIew(v, ev)) {
            if (AppUtils.hideInput(this, v) && isClearFocusWhileAutoHideInputView) {
              v.clearFocus();
            }
          }
        }
      }
      return super.dispatchTouchEvent(ev);
    }
    // 必不可少,否則所有的組件都不會有TouchEvent了
    if (getWindow().superDispatchTouchEvent(ev)) {
      return true;
    }
  }

  try {
    return super.dispatchTouchEvent(ev);
  } catch (Exception e) {
    // ignored
  }
  return false;
}
 
開發者ID:Lingzh0ng,項目名稱:BrotherWeather,代碼行數:29,代碼來源:BaseActivity.java

示例9: hideSoftKeyboard

import android.view.View; //導入方法依賴的package包/類
public static void hideSoftKeyboard(View view) {
    if (view == null) return;
    View mFocusView = view;

    Context context = view.getContext();
    if (context != null && context instanceof Activity) {
        Activity activity = ((Activity) context);
        mFocusView = activity.getCurrentFocus();
    }
    if (mFocusView == null) return;
    mFocusView.clearFocus();
    InputMethodManager manager = (InputMethodManager) mFocusView.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    manager.hideSoftInputFromWindow(mFocusView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:16,代碼來源:TDevice.java

示例10: getViewBitmap

import android.view.View; //導入方法依賴的package包/類
public static Bitmap getViewBitmap(View v) {
    v.clearFocus();
    v.setPressed(false);

    boolean willNotCache = v.willNotCacheDrawing();
    v.setWillNotCacheDrawing(false);

    // Reset the drawing cache background color to fully transparent
    // for the duration of this operation
    int color = v.getDrawingCacheBackgroundColor();
    v.setDrawingCacheBackgroundColor(0);

    if (color != 0) {
        v.destroyDrawingCache();
    }
    v.buildDrawingCache();
    Bitmap cacheBitmap = v.getDrawingCache();
    if (cacheBitmap == null) {
        Log.e("Folder", "failed getViewBitmap(" + v + ")", new RuntimeException());
        return null;
    }

    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

    // Restore the view
    v.destroyDrawingCache();
    v.setWillNotCacheDrawing(willNotCache);
    v.setDrawingCacheBackgroundColor(color);

    return bitmap;
}
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:32,代碼來源:MyBitmapUtil.java

示例11: getViewBitmap

import android.view.View; //導入方法依賴的package包/類
public static Bitmap getViewBitmap(View comBitmap, int width, int height) {
    Bitmap bitmap = null;
    if (comBitmap != null) {
        comBitmap.clearFocus();
        comBitmap.setPressed(false);

        boolean willNotCache = comBitmap.willNotCacheDrawing();
        comBitmap.setWillNotCacheDrawing(false);

        // Reset the drawing cache background color to fully transparent
        // for the duration of this operation
        int color = comBitmap.getDrawingCacheBackgroundColor();
        comBitmap.setDrawingCacheBackgroundColor(0xffffff);
        float alpha = comBitmap.getAlpha();
        comBitmap.setAlpha(1.0f);

        if (color != 0) {
            comBitmap.destroyDrawingCache();
        }

        int widthSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
        comBitmap.measure(widthSpec, heightSpec);
        comBitmap.layout(comBitmap.getLeft(), comBitmap.getTop(), comBitmap.getLeft()+width, comBitmap.getTop()+height);

        comBitmap.buildDrawingCache();
        Bitmap cacheBitmap = comBitmap.getDrawingCache();
        if (cacheBitmap == null) {
            Log.e("view.ProcessImageToBlur", "failed getViewBitmap(" + comBitmap);
            return null;
        }
        bitmap = Bitmap.createBitmap(cacheBitmap);
        // Restore the view
        comBitmap.setAlpha(alpha);
        comBitmap.destroyDrawingCache();
        comBitmap.setWillNotCacheDrawing(willNotCache);
        comBitmap.setDrawingCacheBackgroundColor(color);
    }
    return bitmap;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:41,代碼來源:BitmapCommonUtils.java

示例12: hidePanelAndKeyboard

import android.view.View; //導入方法依賴的package包/類
public static void hidePanelAndKeyboard(View panelLayout) {
    Activity activity = (Activity) panelLayout.getContext();
    View focusView = activity.getCurrentFocus();
    if (focusView != null) {
        KeyboardUtil.hideKeyboard(activity.getCurrentFocus());
        focusView.clearFocus();
    }
    panelLayout.setVisibility(8);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:10,代碼來源:KPSwitchConflictUtil.java

示例13: toBitmap

import android.view.View; //導入方法依賴的package包/類
/**
 * 把view轉化為bitmap(截圖)
 * 參見:http://www.cnblogs.com/lee0oo0/p/3355468.html
 */
public static Bitmap toBitmap(View view) {
    int width = view.getWidth();
    int height = view.getHeight();
    if (view instanceof ListView) {
        height = 0;
        // 獲取listView實際高度
        ListView listView = (ListView) view;
        for (int i = 0; i < listView.getChildCount(); i++) {
            height += listView.getChildAt(i).getHeight();
        }
    } else if (view instanceof ScrollView) {
        height = 0;
        // 獲取scrollView實際高度
        ScrollView scrollView = (ScrollView) view;
        for (int i = 0; i < scrollView.getChildCount(); i++) {
            height += scrollView.getChildAt(i).getHeight();
        }
    }
    view.setDrawingCacheEnabled(true);
    view.clearFocus();
    view.setPressed(false);
    boolean willNotCache = view.willNotCacheDrawing();
    view.setWillNotCacheDrawing(false);
    // Reset the drawing cache background color to fully transparent for the duration of this operation
    int color = view.getDrawingCacheBackgroundColor();
    view.setDrawingCacheBackgroundColor(Color.WHITE);//截圖去黑色背景(透明像素)
    if (color != Color.WHITE) {
        view.destroyDrawingCache();
    }
    view.buildDrawingCache();
    Bitmap cacheBitmap = view.getDrawingCache();
    if (cacheBitmap == null) {
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(cacheBitmap, 0, 0, null);
    canvas.save(Canvas.ALL_SAVE_FLAG);
    canvas.restore();
    if (!bitmap.isRecycled()) {
        LogUtils.verbose("recycle bitmap: " + bitmap.toString());
        bitmap.recycle();
    }
    // Restore the view
    view.destroyDrawingCache();
    view.setWillNotCacheDrawing(willNotCache);
    view.setDrawingCacheBackgroundColor(color);
    return bitmap;
}
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:54,代碼來源:ConvertUtils.java

示例14: toBitmap

import android.view.View; //導入方法依賴的package包/類
/**
 * 把view轉化為bitmap(截圖)
 * 參見:http://www.cnblogs.com/lee0oo0/p/3355468.html
 */
public static Bitmap toBitmap(View view) {
    int width = view.getWidth();
    int height = view.getHeight();
    if (view instanceof ListView) {
        height = 0;
        // 獲取listView實際高度
        ListView listView = (ListView) view;
        for (int i = 0; i < listView.getChildCount(); i++) {
            height += listView.getChildAt(i).getHeight();
        }
    } else if (view instanceof ScrollView) {
        height = 0;
        // 獲取scrollView實際高度
        ScrollView scrollView = (ScrollView) view;
        for (int i = 0; i < scrollView.getChildCount(); i++) {
            height += scrollView.getChildAt(i).getHeight();
        }
    }
    view.setDrawingCacheEnabled(true);
    view.clearFocus();
    view.setPressed(false);
    boolean willNotCache = view.willNotCacheDrawing();
    view.setWillNotCacheDrawing(false);
    // Reset the drawing cache background color to fully transparent for the duration of this operation
    int color = view.getDrawingCacheBackgroundColor();
    view.setDrawingCacheBackgroundColor(Color.WHITE);//截圖去黑色背景(透明像素)
    if (color != Color.WHITE) {
        view.destroyDrawingCache();
    }
    view.buildDrawingCache();
    Bitmap cacheBitmap = view.getDrawingCache();
    if (cacheBitmap == null) {
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(cacheBitmap, 0, 0, null);
    canvas.save(Canvas.ALL_SAVE_FLAG);
    canvas.restore();
    if (!bitmap.isRecycled()) {
       // LogUtils.verbose("recycle bitmap: " + bitmap.toString());
        bitmap.recycle();
    }
    // Restore the view
    view.destroyDrawingCache();
    view.setWillNotCacheDrawing(willNotCache);
    view.setDrawingCacheBackgroundColor(color);
    return bitmap;
}
 
開發者ID:ruiqiao2017,項目名稱:Renrentou,代碼行數:54,代碼來源:ConvertUtils.java

示例15: saveFocusView

import android.view.View; //導入方法依賴的package包/類
private void saveFocusView(View focusView) {
    this.recordedFocusView = focusView;
    focusView.clearFocus();
    this.panelLayout.setVisibility(8);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:6,代碼來源:KPSwitchFSPanelLayoutHandler.java


注:本文中的android.view.View.clearFocus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。