Android界面开发之常用系统控件界面大合集
- 格式:doc
- 大小:505.00 KB
- 文档页数:31
今天我用自己写的一个Demo 和大家详细介绍一个Android开发中遇到的一些常用系统控件的使用技巧。
1.文本框TextView
TextView的作用是用来显示一个文本框,下面我用两种方式为大家呈现TextView,第一种是通过xml布局文件
呈现,第二种是通过代码来呈现,由此可见Android 的界面开发真的是非常灵活。
view plaincopy to clipboardprint?
1. public class TextViewActivity extends Activity {
2. @Override
3. protected void onCreate(Bundle savedInstanceState) {
4. setContentView(yout.textview);
5.
6. LinearLayout ll = (LinearLayout) findViewById(R.id.textviewll);
7. TextView textView = new TextView(this);
8. //设置显示文字
9. textView.setText("从代码中添加一个TextView");
10. //设置显示颜色
11. textView.setTextColor(Color.WHITE);
12. //设置显示字体大小
13. textView.setTextSize(18);
14. //设置显示背景颜色
15. textView.setBackgroundColor(Color.BLUE);
16. //设置锚点位置
17. textView.setGravity(Gravity.CENTER_VERTICAL|Gravity.CE
NTER_HORIZONTAL);
18. //把这个view加入到布局当中
19. ll.addView(textView);
20.
21. super.onCreate(savedInstanceState);
22. }
23. }
1.
2. 3. android:id="@+id/textviewll" 4. android:orientation="vertical"android:layout_width="fill_parent " 5. android:layout_height="fill_parent"> 6. 7. android:layout_width="fill_parent" 8. android:layout_height="wrap_content" 9. android:textColor="#000000" 10. android:textSize="18dip" 11. android:background="#00FF00" 12. android:text="@string/textView" 13. android:gravity="center_vertical|center_horizontal" 14. /> 15.
view plaincopy to clipboardprint?
1. public class WebViewActivity extends Activity {
2. WebView webView = null;
3. static final String MIME_TYPE = "text/html";
4. static final String ENCODING = "utf-8";
5.
6.
7. @Override
8. protected void onCreate(Bundle savedInstanceState) {
9. setContentView(yout.webview);
10.
11. webView = (WebView) findViewById(R.id.webview);
12. webView.loadDataWithBaseURL(null,"欢迎访问雨松MOMO的博客
", MIME_TYPE, ENCODING, null);
13. super.onCreate(savedInstanceState);
14. }
15. }
1.
2. 3. android:id="@+id/textviewll" 4. android:orientation="vertical"android:layout_width="fill_parent " 5. android:layout_height="fill_parent"> 6. 7. android:layout_height="wrap_content" 8. android:textColor="#000000" 9. android:textSize="18dip" 10. android:background="#00FF00" 11. android:text="网页框WebView测试" 12. android:gravity="center_vertical|center_horizontal" 13. /> 14. 15. android:layout_height="wrap_content" 16. android:layout_width="fill_parent"/> 17.