Create a custom dialog box

Source: Internet
Author: User

1. Anti-Open Source China Login Dialog Box. As follows:

2. the dialog is implemented by inheriting the activity. The dialog box can be closed only when the return and close icons are clicked.

3. The main code is logindialog. java. This class is related to login operations, and the specific implementation is more relevant to the business logic.

public class LoginDialog extends Activity{@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.login_dialog);}}

4. click the button to display the dialog box:

Public class mainactivity extends activity {@ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main);} // displayed dialog box public void show (view) {intent = new intent (this, logindialog. class); startactivity (intent) ;}@ overridepublic Boolean oncreateoptionsmenu (menu) {// inflate the menu; this adds items to the action bar if it is present. getmenuinflater (). inflate (R. menu. main, menu); Return true ;}}

5. layout file of the dialog box

<? XML version = "1.0" encoding = "UTF-8"?> <Relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Id = "@ + ID/logindialog_space" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <scrollview Android: id = "@ + ID/login_scrollview" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_centerinparent = "true" Android: paddingtop = "14.0dip" Android: paddingleft = "14.0dip" Android: paddingright = "14.0dip" Android: scrollbars = "NONE"> <viewswitcher Android: Id = "@ + ID/logindialog_view_switcher" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"> <relativelayout Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: background = "@ drawable/login_bg" Android: paddingtop = "30366dip" Android: paddingbottom = "20366dip"> <tablelayout Android: Orientation = "vertical" Android: id = "@ + ID/login_user_table" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_margintop = "10.0dip" Android: layout_marginleft = "15.0dip" android: layout_marginright = "15.0dip" Android: layout_centerhorizontal = "true" Android: Background = "@ drawable/login_user_table_bg"> <linearlayout Android: Id = "@ + ID/login_uly" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_marginleft = "8.0dip" android: layout_margintop = "10.0dip" Android: textstyle = "bold" Android: textcolor = "# ff000000" Android: text = "account:"/> <autocompletetextview Android: id = "@ + ID/login_account" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_margintop = "10.0dip" Android: layout_marginleft = "8.0dip" Android: layout_marginright = "8.0dip" Android: Background = "@ null" Android: hint = "Enter the Account" Android: maxlines = "1" Android: singleline = "true" Android: selectallonfocus = "true" Android: inputtype = "textemailaddress"/> </linearlayout> <imageview Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_margintop = "5.0dip" Android: layout_marginleft = "2.0dip" Android: layout_marginright = "2.0dip" Android: src = "@ drawable/line_blue" Android: scaletype = "fitxy"/> <linearlayout Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_margintop = "7.0dip"> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_marginleft = "8.0dip" Android: textstyle = "bold" Android: textcolor = "# ff000000" Android: TEXT = "Password:"/> <edittext Android: Id = "@ + ID/login_password" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_marginleft = "8.0dip" Android: layout_marginright = "8.0dip" Android: Background = "@ null" Android: hint = "enter the password" Android: maxlines = "1" Android: password = "true" Android: singleline = "true" Android: selectallonfocus = "true"/> </linearlayout> </tablelayout> <tablelayout Android: Orientation = "vertical" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_below = "@ + ID/login_user_table" Android: layout_alignleft = "@ + ID/login_user_table" Android: layout_alignright = "@ + ID/login_user_table" Android: stretchcolumns = "0, 2"> <tablerow Android: gravity = "center_horizontal" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_margintop = "5.0dip"> <checkbox Android: Id = "@ + ID/login_checkbox_rememberme" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_gravity = "Left | Center" Android: paddingleft = "30dip" Android: text = "Remember user name and password" Android: checked = "true"/> </tablerow> <linearlayout Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_margintop = "5.0dip"> <button Android: id = "@ + ID/login_btn_login" Android: layout_width = "fill_parent" Android: layout_height = "45dip" Android: TEXT = "login"/> </linearlayout> </tablelayout> </relativelayout> <view Android: Id = "@ + ID/login_loading" Android: layout_width = "135.0dip" Android: layout_height = "135.0dip" Android: layout_gravity = "center"/> </viewswitcher> </scrollview> <imagebutton Android: id = "@ + ID/login_close_button" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_alignright = "@ + ID/login_scrollview" Android: layout_aligntop = "@ + ID/login_scrollview" Android: Background = "@ drawable/login_close_button_nor"/> </relativelayout>

6. declare in the manifest. xml file. Note that the topic is added; otherwise, no effect is displayed.

 <activity            android:name="com.qj.foschina.ui.LoginDialog"            android:theme="@style/Theme.HalfTranslucent"             >        </activity>

7. Style files

    <style name="Theme.HalfTranslucent" parent="@android:style/Theme.Translucent">        <item name="android:windowBackground">@color/half_transparent</item>        <item name="android:windowNoTitle">true</item>        <item name="android:windowContentOverlay">@null</item>    </style>

Source code: http://download.csdn.net/detail/lzqjfly/5312162

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.