public class Offer_Popup extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.offer_popup);
//newly added code, the window popup
LayoutInflater inflater = (LayoutInflater)
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
PopupWindow pw = new PopupWindow(
inflater.inflate(R.layout.popup_example, null, false),
100,
100,
true);
pw.showAtLocation(this.findViewById(R.id.relativeLayout_popup), Gravity.CENTER, 0, 0);}
/////////////////////
popup_example.xml디버그 다음 안드로이드 코드, 팝업 창
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="Test Pop-Up"
/>
</LinearLayout>
DDMS는 마지막 라인 showAtLocation 오류 보여줍니다.
창을 추가 할 수 없습니다 - 토큰 null이 잘못되었습니다. android.view.WindowManagerBadToken. 팝업을 추가하기 전에 프로그램이 올바르게 실행됩니다. 그러나 팝업 코드가 끝나면 추락했습니다. 무슨 토큰이야?
PW가 팽창 후 유효 ID = 83xxxxxxxx mWindowManager는 유효한 ID = 83xxxxxxx입니다. – lilzz