Android(4.X)学习笔记
Activity启动流程
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:主机域名、虚拟空间、营销软件、网站建设、两当网站维护、网站推广。
Android操作系统 ---> AndroidManifest.xml --->MainAcitivity.onCreate() --->activity_main.xml ...
sp 字体大小会随系统设置的改变而变
dp 字体大小不会随系统设置的改变而变
Ctrl+shift+O 自动导入
Fragment的知识特别重要
public class MainActivity extends Activity { private DatePicker datePicker; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); datePicker = (DatePicker)findViewById(R.id.firstDatePicker); datePicker.updateDate(2013, 4, 10); button = (Button)findViewById(R.id.button); ButtonListener buttonListener = new ButtonListener(); button.setOnClickListener(buttonListener); } class ButtonListener implements OnClickListener{ @Override public void onClick(View v) { int y = datePicker.getYear(); int m = datePicker.getMonth(); int d = datePicker.getDayOfMonth(); System.out.println("y:" + y + ",m" + m + ",d:" + d); Toast.makeText(MainActivity.this, "y:" + y + ",m" + m + ",d:" + d, Toast.LENGTH_SHORT).show(); } } }
public class MainActivity extends Activity { private TimePicker firstTimePicker; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); firstTimePicker = (TimePicker)findViewById(R.id.firstTimePicker); button = (Button)findViewById(R.id.button); //该函数用于设置是否使用24小时制显示时间 firstTimePicker.setIs24HourView(true); TimeListener timeListenter = new TimeListener(); firstTimePicker.setOnTimeChangedListener(timeListenter); ButtonListener buttonListener = new ButtonListener(); button.setOnClickListener(buttonListener); } class ButtonListener implements OnClickListener{ @Override public void onClick(View v) { int hour = firstTimePicker.getCurrentHour(); int minute = firstTimePicker.getCurrentMinute(); Toast.makeText(MainActivity.this, "h:" + hour + ",minute:" + minute, Toast.LENGTH_SHORT).show(); } } class TimeListener implements OnTimeChangedListener{ /** * view:该对象代表着TimePicker * hourOfDay:用户所选择的小时 * minute:用户所选择的分钟 */ @Override public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { System.out.println("Hour:" + hourOfDay + ",minute:" + minute); } } }
public class MainActivity extends Activity { private ProgressBar progressBar; private Button firstButton; private Button secondButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); progressBar = (ProgressBar)findViewById(R.id.firstProgressBar); firstButton = (Button)findViewById(R.id.firstButton); secondButton = (Button)findViewById(R.id.secondButton); progressBar.setMax(100); firstButton.setOnClickListener(new FirstListener()); secondButton.setOnClickListener(new SecondListener()); } class FirstListener implements OnClickListener{ @Override public void onClick(View v) { progressBar.incrementProgressBy(10); } } class SecondListener implements OnClickListener{ @Override public void onClick(View v) { progressBar.incrementSecondaryProgressBy(20); } } }
public class MainActivity extends Activity { private SeekBar seekBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); seekBar = (SeekBar)findViewById(R.id.firstSeekBar); seekBar.setProgress(30); seekBar.setSecondaryProgress(50); SeekBarListener listener = new SeekBarListener(); seekBar.setOnSeekBarChangeListener(listener); } class SeekBarListener implements OnSeekBarChangeListener{ /** * seekBar 该对象指的是触发了监听器的SeekBar对象 * progress 指的是当前SeekBar的进度 * fromUser */ @Override public void onProgressChanged(SeekBar SeekBar, int progress, boolean fromUser) { System.out.println("progress:" + progress + ",fromUser:" + fromUser); Toast.makeText(MainActivity.this, "progress:" + progress + ",fromUser:" + fromUser, Toast.LENGTH_SHORT).show(); } @Override public void onStartTrackingTouch(SeekBar seekBar) { System.out.println("onStart"); } @Override public void onStopTrackingTouch(SeekBar seekBar) { System.out.println("onStop"); } } }
public class MainActivity extends Activity { private RatingBar ratingBar; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ratingBar = (RatingBar)findViewById(R.id.firstRatingBar); button = (Button)findViewById(R.id.button); RatingBarListener listener = new RatingBarListener(); ratingBar.setOnRatingBarChangeListener(listener); ButtonListener buttonListener = new ButtonListener(); button.setOnClickListener(buttonListener); } class ButtonListener implements OnClickListener{ @Override public void onClick(View v) { ratingBar.setRating(ratingBar.getRating() + 1.0f); } } class RatingBarListener implements OnRatingBarChangeListener{ @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { System.out.println("rating:" + rating + ",fromUser:" + fromUser); Toast.makeText(MainActivity.this, "rating:" + rating + ",fromUser:" + fromUser, Toast.LENGTH_SHORT).show(); } } @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; } }
网页题目:Android(4.X)学习笔记
转载注明:http://scyanting.com/article/ipphgs.html