看看WindowManager部分吧,或toast的实现
解决方案 »
- Android TCP 服务出错: null
- Android源代码下载失败
- 求复杂android页面布局代码
- 使用SearchAble呼出搜索框时,如何屏蔽掉系统搜索键呢
- 如何下载android源码
- 如何从SQLite里取得数据放入字符串??
- 请教4.3.1-eabi-armv6 交叉编译工具如何建立
- GridView无法显示图片,提示错误:outofMemory
- android spinner下拉列表右侧箭头颜色怎么设置
- 请问各路大神关于android mediarecorder录像提示start failed问题,在线等
- 最经在做本地音乐播放器,出现java.lang.OutOfMemory的错误
- android外部扩展库的移植方法
public class OnScreenHint {
static final String TAG = "OnScreenHint";
static final boolean LOCAL_LOGV = false; int mGravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
int mX, mY;
float mHorizontalMargin;
float mVerticalMargin;
View mView;
View mNextView; private final WindowManager.LayoutParams mParams =
new WindowManager.LayoutParams();
private final WindowManager mWM;
private final Handler mHandler = new Handler(); /**
* Construct an empty OnScreenHint object. You must call {@link #setView}
* before you can call {@link #show}.
*
* @param context The context to use. Usually your
* {@link android.app.Application} or
* {@link android.app.Activity} object.
*/
public OnScreenHint(Context context) { mWM = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
mY = context.getResources().getDimensionPixelSize(
R.dimen.hint_y_offset);
mParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
mParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
mParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
mParams.format = PixelFormat.TRANSLUCENT;
mParams.windowAnimations = R.style.Animation_OnScreenHint;
/**
* Window type: system overlay windows, which need to be displayed
* on top of everything else. These windows must not take input
* focus, or they will interfere with the keyguard.
*/
mParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;//这地方最关键
//mParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
mParams.setTitle("OnScreenHint");
// params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
// | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
} /**
* Show the view on the screen.
*/
public void show() {
if (mNextView == null) {
throw new RuntimeException("setView must have been called");
}
mHandler.post(mShow);
} /**
* Close the view if it's showing.
*/
public void cancel() {
mHandler.post(mHide);
} /**
* Make a standard hint that just contains a text view.
*
* @param context The context to use. Usually your
* {@link android.app.Application} or
* {@link android.app.Activity} object.
* @param text The text to show. Can be formatted text.
*
*/
public static OnScreenHint makeText(Context context, CharSequence text) {
OnScreenHint result = new OnScreenHint(context);
这地方用你自己的view
LayoutInflater inflate =
(LayoutInflater) context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
View v = inflate.inflate(R.layout.notice, null);
TextView tv = (TextView) v.findViewById(R.id.text);
tv.setText(text); result.mNextView = v; return result;
} /**
* Update the text in a OnScreenHint that was previously created using one
* of the makeText() methods.
* @param s The new text for the OnScreenHint.
*/
public void setText(CharSequence s) {
if (mNextView == null) {
throw new RuntimeException("This OnScreenHint was not "
+ "created with OnScreenHint.makeText()");
}
TextView tv = (TextView) mNextView.findViewById(R.id.text);
if (tv == null) {
throw new RuntimeException("This OnScreenHint was not "
+ "created with OnScreenHint.makeText()");
}
tv.setText(s);
} private synchronized void handleShow() {
if (mView != mNextView) {
// remove the old view if necessary
handleHide();
mView = mNextView;
final int gravity = mGravity;
mParams.gravity = gravity;
if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK)
== Gravity.FILL_HORIZONTAL) {
mParams.horizontalWeight = 1.0f;
}
if ((gravity & Gravity.VERTICAL_GRAVITY_MASK)
== Gravity.FILL_VERTICAL) {
mParams.verticalWeight = 1.0f;
}
mParams.x = mX;
mParams.y = mY;
mParams.verticalMargin = mVerticalMargin;
mParams.horizontalMargin = mHorizontalMargin;
if (mView.getParent() != null) {
mWM.removeView(mView);
}
mWM.addView(mView, mParams);
}
} private synchronized void handleHide() {
if (mView != null) {
// note: checking parent() just to make sure the view has
// been added... i have seen cases where we get here when
// the view isn't yet added, so let's try not to crash.
if (mView.getParent() != null) {
mWM.removeView(mView);
}
mView = null;
}
} private final Runnable mShow = new Runnable() {
public void run() {
handleShow();
}
}; private final Runnable mHide = new Runnable() {
public void run() {
handleHide();
}
};
}