android常用基本代码
身为新手学习安卓往往会特别的迷茫,不知道该学习什么现在提供一些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.setTransformationMethod(PasswordTransformationMethod.getInstance());9 android设置输入框为密码框(xml配置)android:password="true"10 android 提示对话框的使用AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setTitle("你好");builder.setPositiveButton("OK",this);builder.show();需实现android.content.DialogInterface.OnClickListener接口11 android ListView的使用ListView listView = new ListView(this);ArrayList> list = new ArrayList>();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更新ListViewListView listView = new ListView(this);ArrayList> list = new ArrayList>();SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.list,new String[]{"标题"},new int[]{R.id.TextView01});listView.setAdapter(adapter);adapter.notifyDataSetChanged();//通知更新ListView13 android创建LinearLayoutLinearLayout layoutParant = new LinearLayout(this);14 android时间设置对话框的使用DatePickerDialog dlg = new DatePickerDialog(this,this,year,month,day);dlg.show();//year month day 均为int型,第二