In the design of Web pages, front-end designers will often use the JS-based development of the mask layer, and the background translucent. How does this effect happen on Android? This implementation is not difficult, first come on:
<ignore_js_op>
20121029222704.jpg (29.46 KB, download count: $)
Download attachments to albums
2013-5-3 15:29 Upload
This example source download: Click to download
Popmaskviewactivity Code:
[Mw_shl_code=java,true]package Com.sunchis.demo;
import android.app.Activity;
import Android.os.Bundle;
import Android.view.View;
import Android.view.View.OnClickListener;
import Android.widget.Button;
Public class Popmaskviewactivity extends Activity {
/** Called when the activity is first created. * /
@Override
Public void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (r.layout.main);
button button = (button) Findviewbyid (R.id.button);
Button.setonclicklistener (New Onclicklistener () {
@Override
Public void OnClick (View v) {
//Eject mask layer
new Dialogview (Popmaskviewactivity.this). Show ();
}
});
}
}
[/mw_shl_code]
the Dialogview code, which is actually a custom dialog box (Dialog), triggers the pop-up of the Dialog by clicking the button, and its style is controlled in style.xml.
[Mw_shl_code=java,true]package Com.sunchis.demo;
import android.app.Activity;
import Android.app.Dialog;
import Android.view.LayoutInflater;
import Android.view.View;
import Android.view.View.OnClickListener;
import Android.view.Window;
import Android.view.ViewGroup.LayoutParams;
import Android.widget.ImageView;
import android.widget.LinearLayout;
Public class Dialogview {
private Dialog Dialog;
Public Dialogview (Activity mactivity) {
Dialog = New dialog (mactivity, r.style.mask_dialog);
linearlayout Popview = (linearlayout) layoutinflater.
From (mactivity). Inflate (R.layout.dialog_view, null);
//Close button
ImageView viewclose = (ImageView) Popview.findviewbyid (r.id.win_close);
Viewclose.setonclicklistener (New Onclicklistener () {
@Override
Public void OnClick (View v) {
hide ();
}
});
Dialog.setcontentview (Popview,
New Linearlayout.layoutparams (
layoutparams.match_parent, layoutparams.match_parent));
Dialog.setfeaturedrawablealpha (window.feature_options_panel, 0);
}
Public Void Show () {
dialog.show ();
}
Public void Hide () {
Dialog.dismiss ();
}
} [/mw_shl_code]
The dialog box (Dialog) style Style.xml code, which is set through the "New Dialog (context, Theme)" method.
[Mw_shl_code=java,true]<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<!--mask Layer properties that mimic dialog-
<style name= "Mask_dialog" parent= "@android: Style/theme.dialog" >
<item name= "android:windowisfloating" >true</item>
<item name= "android:windowistranslucent" >true</item>
<item name= "Android:windownotitle" >true</item>
<item name= "Android:windowbackground" > @null </item>
<item name= "android:backgrounddimenabled" >true</item>
</style>
</resources> [/mw_shl_code]
Finally, the layout code of the mask layer is:
[Mw_shl_code=xhtml,true]<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:background= "@drawable/dialog"
android:orientation= "vertical" >
<linearlayout
android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:background= "@drawable/title" >
<imageview
android:id= "@+id/win_close"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:src= "@drawable/close"/>
<textview
android:id= "@+id/win_title"
android:layout_width= "Wrap_content"
android:layout_height= "Match_parent"
android:layout_weight= "1.05"
android:gravity= "center"
android:text= "@string/view_title"
android:textcolor= "#ffffff"
android:textsize= "20sp"/>
<imageview
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:src= "@drawable/default_button"/>
</LinearLayout>
</LinearLayout> [/mw_shl_code]
Some of the picture materials involved are not listed, But are included in the source package, it is recommended to download the source for research and learning!