亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 1336 | 回復(fù): 0
打印 上一主題 下一主題

[Android] 簡(jiǎn)單UI設(shè)計(jì) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2015-05-27 14:28 |只看該作者 |倒序?yàn)g覽
本帖最后由 rocox 于 2015-05-27 14:28 編輯


關(guān)鍵技術(shù):

      用到了本地化控件:SharedPreferences,簡(jiǎn)單的說(shuō)就是本地配置。

     四大組件:Intent

基本思路請(qǐng)看代碼:

  Java代碼:

  1. 1 import android.os.Bundle;
  2. 2 import android.app.Activity;
  3. 3 import android.content.Context;
  4. 4 import android.content.Intent;
  5. 5 import android.content.SharedPreferences;
  6. 6 import android.view.Menu;
  7. 7 import android.view.View;
  8. 8 import android.view.View.OnClickListener;
  9. 9 import android.widget.Button;
  10. 10 import android.widget.CheckBox;
  11. 11 import android.widget.EditText;
  12. 12 import android.widget.Toast;
  13. 13
  14. 14 public class MainActivity extends Activity {
  15. 15     private Button  logIn;
  16. 16     private CheckBox rember,auto;
  17. 17     private EditText name,password;
  18. 18     private SharedPreferences test;
  19. 19     private SharedPreferences.Editor editor;
  20. 20     private boolean haved;
  21. 21     @Override
  22. 22     protected void onCreate(Bundle savedInstanceState) {
  23. 23         super.onCreate(savedInstanceState);
  24. 24         setContentView(R.layout.activity_main);
  25. 25         
  26. 26         logIn= (Button) findViewById(R.id.button1);
  27. 27         rember=(CheckBox) findViewById(R.id.remberFlag);
  28. 28         auto=(CheckBox)    findViewById(R.id.autoRunFlag);
  29. 29         name=(EditText) findViewById(R.id.name);
  30. 30         password=(EditText) findViewById(R.id.password);
  31. 31         final Intent intent=new Intent(MainActivity.this,NewMainActivity.class);
  32. 32         //打開(kāi) 或 創(chuàng)建一個(gè)名為UserData的xml文件
  33. 33         test=getSharedPreferences("UserData", Context.MODE_PRIVATE);
  34. 34         editor=test.edit();
  35. 35         
  36. 36         if(test.getBoolean("auto",false)!=false)
  37. 37         {
  38. 38             startActivity(intent);
  39. 39         }
  40. 40         
  41. 41         if(test.getBoolean("rember", false)!=false)
  42. 42             {
  43. 43                 String temp;
  44. 44                 if((temp=test.getString("name", null))!=null)
  45. 45                     name.setText(temp);
  46. 46                 if((temp=test.getString("password",null)) != null)
  47. 47                     password.setText(temp);
  48. 48                 rember.setChecked(true);
  49. 49                 haved=true;
  50. 50             }
  51. 51         
  52. 52         logIn.setOnClickListener(new View.OnClickListener() {   
  53. 53             @Override
  54. 54             public void onClick(View v) {
  55. 55                 if(haved == false )
  56. 56                 {
  57. 57                     if(rember.isChecked())
  58. 58                     {
  59. 59                         editor.putBoolean("rember", true);
  60. 60                         editor.putString("name", name.getText().toString());
  61. 61                         editor.putString("password", password.getText().toString());
  62. 62                         editor.commit();
  63. 63                     }
  64. 64                     if(auto.isChecked()==true)
  65. 65                         editor.putBoolean("auto", true);        
  66. 66                 }
  67. 67                 startActivity(intent);
  68. 68             }
  69. 69         });
  70. 70     }
  71. 71 }
  72. 復(fù)制代碼
  73.   activity_main.xml

  74. 復(fù)制代碼
  75. 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  76. 2     xmlns:tools="http://schemas.android.com/tools"
  77. 3     android:layout_width="match_parent"
  78. 4     android:layout_height="match_parent"
  79. 5     android:paddingBottom="@dimen/activity_vertical_margin"
  80. 6     android:paddingLeft="@dimen/activity_horizontal_margin"
  81. 7     android:paddingRight="@dimen/activity_horizontal_margin"
  82. 8     android:paddingTop="@dimen/activity_vertical_margin"
  83. 9     tools:context=".MainActivity" >
  84. 10
  85. 11     <EditText
  86. 12         android:id="@+id/name"
  87. 13         android:layout_width="match_parent"
  88. 14         android:layout_height="wrap_content"
  89. 15         android:layout_alignLeft="@+id/password"
  90. 16         android:layout_alignParentTop="true"
  91. 17         android:layout_marginTop="16dp"
  92. 18         android:ems="10" />
  93. 19
  94. 20     <EditText
  95. 21         android:id="@+id/password"
  96. 22         android:layout_width="match_parent"
  97. 23         android:layout_height="wrap_content"
  98. 24         android:layout_below="@+id/name"
  99. 25         android:layout_centerHorizontal="true"
  100. 26         android:layout_marginTop="18dp"
  101. 27         android:ems="10" >
  102. 28
  103. 29         <requestFocus />
  104. 30     </EditText>
  105. 31
  106. 32     <Button
  107. 33         android:id="@+id/button1"
  108. 34         android:layout_width="wrap_content"
  109. 35         android:layout_height="wrap_content"
  110. 36         android:layout_alignLeft="@+id/password"
  111. 37         android:layout_below="@+id/password"
  112. 38         android:layout_marginLeft="16dp"
  113. 39         android:text="登陸" />
  114. 40
  115. 41     <CheckBox
  116. 42         android:id="@+id/autoRunFlag"
  117. 43         android:layout_width="wrap_content"
  118. 44         android:layout_height="wrap_content"
  119. 45         android:layout_alignLeft="@+id/password"
  120. 46         android:layout_below="@+id/button1"
  121. 47         android:text="自動(dòng)登陸" />
  122. 48
  123. 49     <CheckBox
  124. 50         android:id="@+id/remberFlag"
  125. 51         android:layout_width="wrap_content"
  126. 52         android:layout_height="wrap_content"
  127. 53         android:layout_alignBaseline="@+id/autoRunFlag"
  128. 54         android:layout_alignBottom="@+id/autoRunFlag"
  129. 55         android:layout_alignRight="@+id/password"
  130. 56         android:text="記住密碼" />
  131. 57
  132. 58 </RelativeLayout>
  133. 復(fù)制代碼
  134. activity_second.xml:

  135. 復(fù)制代碼
  136. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  137.     xmlns:tools="http://schemas.android.com/tools"
  138.     android:layout_width="match_parent"
  139.     android:layout_height="match_parent"
  140.     android:paddingBottom="@dimen/activity_vertical_margin"
  141.     android:paddingLeft="@dimen/activity_horizontal_margin"
  142.     android:paddingRight="@dimen/activity_horizontal_margin"
  143.     android:paddingTop="@dimen/activity_vertical_margin"
  144.     tools:context=".MainActivity" >

  145.     <RatingBar
  146.         android:id="@+id/ratingBar1"
  147.         android:layout_width="wrap_content"
  148.         android:layout_height="wrap_content"
  149.         android:layout_alignParentTop="true"
  150.         android:layout_centerHorizontal="true"
  151.         android:layout_marginTop="170dp" />

  152. </RelativeLayout>
復(fù)制代碼
AndroidMainifest中要注冊(cè):
  1. <activity
  2.             android:name="com.example.log_in.NewMainActivity"
  3.             android:label="second_activity" >
  4.         </activity>
復(fù)制代碼
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP