Demo03:基本控件
来源:互联网 发布:网络教育需要到学校吗 编辑:程序博客网 时间:2024/06/04 17:49
package com.wuqiong.demo03;import android.app.Activity;import android.graphics.Color;import android.os.Bundle;import android.text.method.HideReturnsTransformationMethod;import android.text.method.PasswordTransformationMethod;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.EditText;import android.widget.TextView;public class MainActivity extends Activity {private TextView mytext;private Button button1;private Button button2;private Button button3;private EditText edit;private CheckBox check;private static int num = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mytext = (TextView) findViewById(R.id.mytext); button1 = (Button) findViewById(R.id.button1); button2 = (Button) findViewById(R.id.button2); button3 = (Button) findViewById(R.id.button3); edit = (EditText) findViewById(R.id.edit); check = (CheckBox) findViewById(R.id.check); button1.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {mytext.setTextSize(24);}}); button2.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {mytext.setTextSize(16);}}); button3.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {num++;switch(num%4){case 1:mytext.setBackgroundColor(Color.RED);break;case 2:mytext.setBackgroundColor(Color.YELLOW);break;case 3:mytext.setBackgroundColor(Color.BLUE);break;case 0:mytext.setBackgroundColor(Color.GREEN);break;}}}); check.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {if(check.isChecked())edit.setTransformationMethod(HideReturnsTransformationMethod.getInstance());elseedit.setTransformationMethod(PasswordTransformationMethod.getInstance());}}); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }}
<pre name="code" class="html"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.wuqiong.demo03.MainActivity" > <TextView android:id="@+id/mytext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:textSize="20sp" android:text="@string/mytext" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/mytext" android:layout_alignParentLeft="true" android:text="@string/enlarge"/> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/mytext" android:layout_toRightOf="@id/button1" android:text="@string/shrink"/> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/mytext" android:layout_toRightOf="@id/button2" android:text="@string/color"/><EditText android:id="@+id/edit" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/button1" android:inputType="numberPassword" android:hint="@string/type"/><CheckBox android:id="@+id/check" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/edit" android:text="@string/display"/></RelativeLayout>
0 0
- Demo03:基本控件
- SlidingFragment左右滑动 Demo03
- demo03——汉诺塔问题
- 基本控件
- 基本控件
- 基本控件
- 基本控件
- 基本控件
- 基本控件
- 基本控件
- 基本常用控件基本用法
- 基本常用控件基本用法
- 07_VB6基本控件
- CheckBoxList控件基本用法
- dialog控件基本用法
- 基本控件小经验
- .NET基本控件
- 基本控件:1,Button
- 在Ubuntu下搭建Apache(阿帕奇)服务
- matlab命令小常识
- 2015-5-10分享的PDF
- 100个你从没听说过的超有用资料网站 - 转自[译言网]
- day18/day18_IO/FileWriterDemo.java
- Demo03:基本控件
- traceroute的一些用法
- C++文件读写操作
- 插入排序
- day19/BufferedReaderDemo.java
- js及jquery获取页面和元素的宽高
- 颜色代码大全
- Makefile 好的语句积累
- 构建施耐德楼控系统数据库后台服务器示例工程—(工程创建)