我创建了一个看起来像对话框的活动。这就是我要做的事情
requestWindowFeature(Window.FEATURE_NO_TITLE);
Display display = getWindow().getWindowManager().getDefaultDisplay();
LayoutParams params = getWindow().getAttributes();
params.height = (display.getHeight()*3)/4;
params.width = (display.getWidth()) / 2;
params.alpha = 1.0f;
params.dimAmount = 0.5f;
params.gravity=Gravity.TOP | Gravity.RIGHT;;
getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
setContentView(R.layout.search_activity);
LinearLayout layout = (LinearLayout)findViewById(R.id.root);
LinearLayout.LayoutParams lp = new
LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
lp.setMargins(0, getIntent().getExtras().getInt("height"), 0, 0);
layout.setLayoutParams(lp);
我曾经创建过这个
的样式 <style name="PopupTheme" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowSoftInputMode">stateAlwaysHidden</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowCloseOnTouchOutside">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
这就是我获得的:
蓝色区域是一项活动。实际上我会触摸到我的活动必须从视图中消失的活动。它正在工作。但是活动还没有完成。我想在触摸它时完成它
我尝试了this.setFinishOnTouchOutside(true);
和
@Override
public boolean onTouchEvent(MotionEvent event) {
// If we've received a touch notification that the user has touched
// outside the app, finish the activity.
if (MotionEvent.ACTION_OUTSIDE == event.getAction()) {
finish();
return true;
}
// Delegate everything else to Activity.
return super.onTouchEvent(event);
}
我知道这一行<item name="android:windowCloseOnTouchOutside">true</item>
有助于从视图中关闭活动。但是有没有办法以编程方式访问此属性。
但是没有帮助我。可以告诉我怎样才能实现它?
答案 0 :(得分:0)
试试这个
public void onPause(){
super.onPause();
finish();
}