代碼修改 drawleft 圖標(biāo)大小
Drawable drawable = getResources().getDrawable(int drawableId);
drawable.setBounds(0, 0, width, height);(一定要先設(shè)置這個)
radioButton.setCompoundDrawables(null, null, drawable, null);(要使用這個方法設(shè)置圖片才能生效)
控制EditText不讓輸入中文(輸入內(nèi)容類型)
自定義EditText重寫onCreateInputConnection()方法
在該方法內(nèi)返回自定義的MyInputConnecttion
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
return new MyInputConnecttion(super.onCreateInputConnection(outAttrs),
false);
}
創(chuàng)建MyInputConnecttion繼承InputConnectionWrapper實現(xiàn)InputConnection在commitText()方法內(nèi)部控制不能輸入或者可輸入的文字類型
class MyInputConnecttion extends InputConnectionWrapper implements InputConnection {
public MyInputConnecttion(InputConnection target, boolean mutable) {
super(target, mutable);
}
/**
* 對輸入的內(nèi)容進行攔截
*/
@Override
public boolean commitText(CharSequence text, int newCursorPosition) {
// 不能輸入漢字
if (text.toString().matches("[\u4e00-\u9fa5]+")) {
return false;
}
return super.commitText(text, newCursorPosition);
}
}
讓popuwindow的父類上的控件處理Touch事件,不讓自處理
public static void setPopupWindowTouchModal(PopupWindow popupWindow,
boolean touchModal) {
if (null == popupWindow) {
return;
}
Method method;
try {
method = PopupWindow.class.getDeclaredMethod("setTouchModal",
boolean.class);
method.setAccessible(true);
method.invoke(popupWindow, touchModal);
} catch (Exception e) {
e.printStackTrace();
}
}
android7.0 popuwindow顯示位置錯誤(全屏置頂)
public void showPopupWindow(PopupWindow popupWindow, View view) {
if (Build.VERSION.SDK_INT < 24) {
popupWindow.showAsDropDown(view);
} else {
int[] location = new int[2];
view.getLocationOnScreen(location);
int y = location[1];
popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, 0, y + view.getHeight());
}
}