当前位置: 首页>>代码示例>>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;未经允许,请勿转载。