码迷,mamicode.com
首页 > 其他好文 > 详细

屏幕手势向导页面---愿好心人来解决BUG

时间:2015-06-05 14:02:33      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:dialog context 手势 引

项目地址 http://download.csdn.net/detail/u013210620/8775407

技术分享

此Demo有一个奇葩的bug
06-05 12:50:44.955: E/AndroidRuntime(16374): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@41d0c028 is not valid; is your activity running?
在IDE项目上直接运行没有错误,但是在手机上运行就有时候报错,有时候正常,我表达的有点语无伦次,望高手作答
搜了下网上的原因,多数都说上下文参数错误

regist.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:id="@+id/et_tel"
        android:layout_width="fill_parent"
        android:layout_height="47dp"
        android:layout_marginLeft="17dp"
        android:layout_marginRight="17dp"
        android:layout_marginTop="50dp"
        android:background="@drawable/bg_input"
        android:hint="请输入手机号码"
        android:paddingLeft="17dp"
        android:paddingRight="17dp"
        android:textColor="#666666"
        android:textColorHint="#bbbbbb"
        android:textSize="16dp"
        android:typeface="sans" />

</RelativeLayout>

guide_registe.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root_guide_contact_dialog"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <ImageView 
        android:id="@+id/img_registe_input"
        android:layout_width="fill_parent"
        android:layout_height="47dp"
        android:layout_marginTop="50dp"
        android:background="@drawable/bg_registe_input"/>
    <ImageView 
        android:id="@+id/img_registe_tip"
        android:layout_width="fill_parent"
        android:layout_height="155dp"
        android:layout_marginTop="120dp"
        android:background="@drawable/bg_registe_tip"/>

</RelativeLayout>

MainActivity
package com.example.guideregiste;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.EditText;

public class MainActivity extends Activity {
	public EditText et_tel;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//去头部
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		//加载布局文件
		setContentView(R.layout.regist);
		//获取控件
		et_tel =(EditText)findViewById(R.id.et_tel);
        
		//显示alertDialog
		RegisteFunctionGuideDlg.getInstance(MainActivity.this,et_tel).show();
	}
}


RegisteFunctionGuideDlg
package com.example.guideregiste;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;

public class RegisteFunctionGuideDlg extends Dialog {
	
	
	private Context context ;
	private static View mClickView;
	private static RegisteFunctionGuideDlg functionGuideDlg = null;
	/**构造器*/
	private RegisteFunctionGuideDlg(Context context) {
		//全屏
		super(context, android.R.style.Theme_Translucent_NoTitleBar);
		this.context = context;
	}
	public static RegisteFunctionGuideDlg getInstance(Context ctx,View view) {  
		mClickView = view;
		
        if (functionGuideDlg == null) {    
        	functionGuideDlg = new RegisteFunctionGuideDlg(ctx);  
        }    
       return functionGuideDlg;  
   } 
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.guide_registe);
		//获取dialog的布局id
		View rootView = findViewById(R.id.root_guide_contact_dialog);
		//设置颜色背景
		rootView.setBackgroundColor(Color.argb(150, 0, 0, 0)) ;
		ImageView img_input = (ImageView)findViewById(R.id.img_registe_input)  ;
		img_input.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dismiss();
			}
		})  ;
		getWindow().setGravity(Gravity.TOP);
	}
}


屏幕手势向导页面---愿好心人来解决BUG

标签:dialog context 手势 引

原文地址:http://blog.csdn.net/u013210620/article/details/46375143

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!