์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- Android
- SQL
- ์ค๋ธ์
- ์ฝํ
- ์นด์นด์ค์ฝํ
- groupby
- ์ฝํ๋ฆฐ
- select
- ํผ๊ณตํ
- CS
- ์๋๋ก์ด๋
- ๊ธฐ์ ๋ฉด์
- ํผ๊ณต์ฑ๋ฆฐ์ง
- ์๋ฐ
- ํฐ์คํ ๋ฆฌ์ฑ๋ฆฐ์ง
- join
- ํผ๊ณต๋จ
- Kotlin
- ์๋๋ก์ด๋์คํ๋์ค
- MySQL
- ์ธํ๋ฐ
- Til
- ์คํฐ๋
- ์ ์ฒ๊ธฐ
- ์๊ณ ๋ฆฌ์ฆ
- ์๋ฃ๊ตฌ์กฐ
- ์ ๋ณด์ฒ๋ฆฌ๊ธฐ์ฌ
- ํ๋ก๊ทธ๋๋จธ์ค
- doitandroid
- java
- Today
- Total
Welcome! Everything is fine.
[Android] ํ ์คํธ, ์ค๋ต๋ฐ, ์๋ฆผ ๋ํ์์ ๋ณธ๋ฌธ
๐ํ ์คํธ(Toast)
ํ ์คํธ๋ ๋ค์๊ณผ ๊ฐ์ด ๊ฐ๋จํ ๋ฉ์ธ์ง๋ฅผ ์ ๊น ๋ณด์ฌ์คฌ๋ค๊ฐ ์ฌ๋ผ์ง๋ ๋ทฐ๋ก, ๋๋ฒ๊น ๋ฉ์ธ์ง๋ฅผ ํ์ธํด๋ณด๊ฑฐ๋ ์ฌ์ฉ์์๊ฒ ๊ฐ๋จํ ๋ฉ์ธ์ง๋ฅผ ๋์ธ ๋ ์์ฃผ ์ฌ์ฉํ๋ค.
ํ ์คํธ ๋ฉ์ธ์ง๋ฅผ ๋ง๋๋ ๊ธฐ๋ณธ์ ์ธ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ๋ค.
Toast.makeText(Context context, String message, int duration).show();
โ ํ ์คํธ ๋ทฐ ์์น ์ง์ ๋ฉ์๋
public void setGravity(int gravity, int xOffset, int yOffset)
โ ํ ์คํธ ๋ทฐ์ ์ธ๋ถ ์ฌ๋ฐฑ ์ง์ ๋ฉ์๋
public void setMargin(float horizontalMargin, float verticalMargin)
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onButton1Clicked(View v) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toastborder,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView text = layout.findViewById(R.id.text);
Toast toast = new Toast(this);
text.setText("๋ชจ์ ๋ฐ๊พผ ํ ์คํธ");
toast.setGravity(Gravity.CENTER, 0, -100);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
}
๐์ค๋ต๋ฐ(Snackbar)
์ค๋ต๋ฐ ์ญ์ ๊ฐ๋จํ ๋ฉ์ธ์ง๋ฅผ ๋์ธ ๋ ์ฌ์ฉํ๋ค. ๋ฒํผ์ ํ๋ ๋ ๋ง๋ค๊ณ , ๋ค์๊ณผ ๊ฐ์ด MainActivity.java์ OnButton2Clicked ๋ฉ์๋๋ฅผ ๋ฃ๊ณ ์ฐ๊ฒฐํ๋ค.
public void onButton2Clicked(View v) {
Snackbar.make(v,"์ค๋ต๋ฐ์
๋๋ค.", Snackbar.LENGTH_LONG).show();
}
์คํํด๋ณด๋ฉด ํ๋ฉด ์๋์ชฝ์์ ์ฌ๋ผ์ค๋ ์ค๋ต๋ฐ๋ฅผ ๋ณผ ์ ์๋ค.
๐์๋ฆผ ๋ํ์์
์๋ฆผ ๋ํ์์๋ ์ฌ์ฉ์์๊ฒ ํ์ธ์ ๋ฐ๊ฑฐ๋ ์ ํํ๊ฒ ํ ๋ ์ฌ์ฉํ๋ค. AlertDialog ํด๋์ค๋ก ์ฝ๊ฒ ์๋ฆผ ๋ํ์์๋ฅผ ๋ณด์ฌ์ค ์ ์๋ค. setTitle, setMessage, setIcon ๋ฉ์๋๋ก ํ์ดํ, ๋ด์ฉ, ์์ด์ฝ์ ์ค์ ํ ์ ์๋ค. ๋ํ setPositiveButton๊ณผ setNegativeButton ๋ฉ์๋๋ก '์', '์๋์ค'์ ๊ฐ์ ๋ฒํผ์ ์ค์ ์ ํ ์ ์๋ค.
public class MainActivity extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showMessage();
}
});
}
private void showMessage() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("์๋ด");
builder.setMessage("์ข
๋ฃํ์๊ฒ ์ต๋๊น?");
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setPositiveButton("์", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String message = "์ ๋ฒํผ์ด ๋๋ ธ์ต๋๋ค.";
textView.setText(message);
}
});
builder.setNegativeButton("์๋์ค", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String message = "์๋์ค ๋ฒํผ์ด ๋๋ ธ์ต๋๋ค.";
textView.setText(message);
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
}
์ฑ์ ์คํํ๋ฉด ๋ค์๊ณผ ๊ฐ์ ๊ฒฐ๊ณผ๊ฐ ๋์จ๋ค. ๋ํ ์ด๋ ๋ต๋ณ์ ์ ํํ๋์ง์ ๋ฐ๋ผ ํ ์คํธ๊ฐ ๋ฐ๋๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
'Android' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Android] ์ธํ๋ ์ด์ (0) | 2022.03.09 |
---|---|
[Android] ํ๋ก๊ทธ๋ ์ค๋ฐ (0) | 2022.03.06 |
[Android] No speakable text present ์๋ฌ (0) | 2022.03.04 |
[Android] ์ด๋ฒคํธ ์ฒ๋ฆฌ (0) | 2022.03.02 |
[Android] ๋๋ก์ด๋ธ ๋ง๋ค๊ธฐ (0) | 2022.03.02 |