自定义无标题Dialog

1.主Activity:
 
public class DialogShow extends Activity {

	private OnClickListener btnListener;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Button btn = (Button) findViewById(R.id.Button01);
		btnListener = new View.OnClickListener() {
			public void onClick(View view) {
				new Tip(DialogShow.this).show();
			}
		};
		btn.setOnClickListener(btnListener);
	}
}
  


2.Tip.java:
public class Tip {

	private ImageView image;
	private Dialog mDialog;

	public Tip(Context context) {
		mDialog = new Dialog(context, R.style.dialog);
		Window window = mDialog.getWindow();
		WindowManager.LayoutParams wl = window.getAttributes();
		wl.x = 30;
		wl.y = 20;
		window.setAttributes(wl);
		window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
		// window.setGravity(Gravity.BOTTOM|Gravity.FILL_HORIZONTAL);
		window.setLayout(ViewGroup.LayoutParams.FILL_PARENT,
				ViewGroup.LayoutParams.WRAP_CONTENT);
		mDialog.setContentView(R.layout.tip);
		mDialog.setFeatureDrawableAlpha(Window.FEATURE_OPTIONS_PANEL, 0);
		image = (ImageView) mDialog.findViewById(R.id.image);
		image.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				mDialog.dismiss();
			}
		});
	}
	
	public void show(){
		mDialog.show();
	}

}


3.styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
	<style name="dialog" parent="@android:style/Theme.Dialog">
		<item name="android:windowFrame">@null</item>
		<item name="android:windowIsFloating">true</item>
		<item name="android:windowIsTranslucent">false</item>
		<item name="android:windowNoTitle">true</item>
		<item name="android:windowBackground">@null</item>
		<item name="android:backgroundDimEnabled">false</item>
	</style>
</resources>


4.tip.xml:
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="300dp" android:layout_height="190dp"
	android:orientation="vertical" android:background="@drawable/belle_frame">


	<LinearLayout android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:orientation="horizontal"
		android:id="@+id/upContent" android:layout_marginTop="10dp"
		android:layout_marginLeft="3dp">
		<ImageView android:id="@+id/image" android:layout_width="80dp"
			android:layout_height="120dp" />
		<TextView android:id="@+id/description" android:layout_width="220dp"
			android:layout_height="wrap_content"
			android:text="1.this is the test text!\n
			1.this is the test text!\n1.this is the test text!\n1.this is the test text!\n
			1.this is the test text!\n1.this is the test text!\n1.this is the test text!\n" />
	</LinearLayout>
</LinearLayout>
 

你可能感兴趣的:(java,xml)