身为新手学习安卓往往会特别的迷茫,不知道该学习什么现在提供一些Android在学习的过程当中经常用到的一些语句,以方便大家学习
0 android创建按钮
Button button = new Button(this);
1 android创建输入框
EditText editText = new EditText(this);
2 android创建文本
TextView textView = new TextView(this);
3 android设置文本显示内容
TextView textView = new TextView(this);
textView.setText("hello world!");
4 android设置文本背景
TextView textView = new TextView(this);
textView.setBackgroundColor(Color.YELLOW);
5 android设置文本颜
TextView textView = new TextView(this);
textView.setTextColor(Color.YELLOW);
6 android设置文本文字大小
TextView textView = new TextView(this);
textView.setTextSize(18);
7 android设置输入框宽度
EditText editText = new EditText(this);
editText.setWidth(200);
8 android设置输入框为密码框
EditText editText = new EditText(this);
editText.Instance());
9 android设置输入框为密码框(xml配置)
android:password="true"
10 android 提示对话框的使用
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("你好");
builder.setPositiveButton("OK",this);
builder.show();
需实现t.DialogInterface.OnClickListener接口
11 android ListView的使用
ListView listView = new ListView(this);
ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.list,new String[]{"标题"},new int[]{R.id.TextView01});
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
然后实现OnItemClickListener接口
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {}
12 android更新ListView
ListView listView = new ListView(this);
ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.list,new String[]{"标题"},new int[]{R.id.TextView01});
listView.setAdapter(adapter);
ifyDataSetChanged();//通知更新ListView
13 android创建LinearLayout
LinearLayout layoutParant = new LinearLayout(this);
14 android时间设置对话框的使用
DatePickerDialog dlg = new DatePickerDialog(this,this,year,month,day);
dlg.show();
//year month day 均为int型,第二个参数为this时,该类需要implements OnDateSetListener并重写以下方法
public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
}
15 android创建FrameLayout
FrameLayout layout = new FrameLayout(this);
16 android触发键盘事件
layout.setOnKeyListener(this);
//需要implements OnKeyListener并重写以下方法
public boolean onKey(View v, int keyCode, KeyEvent event) {
    return false;//返回是否销毁该事件以接收新的事件,比如返回true按下时可以不断执行这
个方法,返回false则执行一次。
}
17 android触发鼠标事件
layout.OnTouchListener(this);
//需要implements OnTouchListener并重写以下方法
public boolean onTouch(View v, MotionEvent event) {
    return false;//返回是否销毁该事件以接收新的事件,比如返回true按下时可以不断执行这个方法,返回false则执行一次。
}
18 android获得屏幕宽度和高度
int width = Window().getWindowManager().getDefaultDisplay().getWidth();
int height =Window().getWindowManager().getDefaultDisplay().getHeight();
19 android布局添加控件
LinearLayout layout = new LinearLayout(this);
Button button = new Button(this);
layout.addView(button);
20 android intent实现activit之间跳转
Intent intent = new Intent();
intent.setClass(this, DestActivity.class);
startActivity(intent);
21 android intent设置action
Intent intent = new Intent();
intent.setAction(intent.ACTION_DIAL);
22 android intent设置data
Intent intent = new Intent();
intent.setData(Uri.parse("tel:00000000"));
23 android intent传数据
Intent intent = new Intent();
intent.putExtra("data", value);//value可以是很多种类型,在接收activity中取出后强制转换或调用相应类型的get函数。
24 android intent取数据
String value = (String)getIntent().getExtras().get("data");
//or String value = getIntent().getExtras().getString("data");
25 android利用paint和canvas画图
setContentView(new MyView(this));
class MyView extends View{
    public MyView(Context context){
        super(context);
    }
    public void onDraw(Canvas canvas){
        Paint paint = new Paint();//创建画笔
        paint.setColor(Color.BLUE);//设置画笔颜
        canvas.drawRect(0, 0, 100, 100, paint);//画个正方形,坐标0,0,100,100。
    }
}
26 android新建对话框
Dialog dialog = new Dialog(this);
dialog.setTitle("test");//设置标题
dialog.addContentView(button,new LayoutParams(-1,-1));//添加控件,-1是设置高度和宽度充满布局,-2是按照需要设置宽度高度。
dialog.show();
27 android取消对话框
dialog.cancel();
28 android对View类刷新显示
view.invalidate();//通过这个调用view的onDraw()函数