안드로이드

자주쓰는 코드

좋은향기 2018. 5. 13. 06:46
반응형

코드


* 리소스 얻기

Button button1 = findViewById(R.id.button1);


* Listener 설정

button1.setOnClickListener( new View.OnClickListener() {

public void onClick(View v) {

// to do

}

});;



* Toast 사용

Toast.makeText(getApplicationContext(), "버튼클릭", Toast.LENGTH_SHORT).show();


* 브라우징

Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.naver.com"));

startActivity(mIntent);


* 전화

Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:/114"));startActivity(mIntent);


*갤러리

Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/internal/images/media"));

startActivity(mIntent);


*종료

finish();


현재 날짜 구하기

Calendar cal = Calendar.getInstance();
int cYear = cal.get(Calendar.YEAR);
int cMonth = cal.get(Calendar.MONTH);
int cDay = cal.get(Calendar.DAY_OF_MONTH); 

datePicker.init(cYear, cMonth, cDay, new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
String date = Integer.toString(year) + "_" + Integer.toString(monthOfYear+1) + "_" + Integer.toString(dayOfMonth);
}
});



그외

상단 앱아이콘 설정

1) IMG: 72x72 png

res/drawable/ic_luncher.png

2) code : MainActivity

onCreate()

{

 getSupportActionBar().setDisplayShowHomeEnabled(true);

 getSupportActionBar().setIcon(R.drawable.ic_luncher);

}



반응형