Activity啟動(dòng)流程
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:主機(jī)域名、虛擬空間、營銷軟件、網(wǎng)站建設(shè)、兩當(dāng)網(wǎng)站維護(hù)、網(wǎng)站推廣。
Android操作系統(tǒng) ---> AndroidManifest.xml --->MainAcitivity.onCreate() --->activity_main.xml ...
sp 字體大小會(huì)隨系統(tǒng)設(shè)置的改變而變
dp 字體大小不會(huì)隨系統(tǒng)設(shè)置的改變而變
Ctrl+shift+O 自動(dòng)導(dǎ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); //該函數(shù)用于設(shè)置是否使用24小時(shí)制顯示時(shí)間 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:用戶所選擇的小時(shí) * 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 該對象指的是觸發(fā)了監(jiān)聽器的SeekBar對象 * progress 指的是當(dāng)前SeekBar的進(jìn)度 * 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; } }