0
我創建了一個活動看起來像對話框。這個我就是這樣做實現對話活動一樣不精觸摸外面
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>
有助於從視圖中關閉活動。但有以編程方式訪問此屬性的任何方式。 但沒有幫助我。可以有人告訴我,我怎麼能實現它?