Skip to content

Instantly share code, notes, and snippets.

public class Example extends Activity
implements OnClickListener {
protected void onCreate(Bundle savedValues) {
// 구현부분
Button button = (Button)findViewById(R.id.btn);
button.setOnClickListener(this);
}
public void onClick(View v) {
// 구현부분
}
<LinearLayout
android:orientation="vertical"
... >
<Button android:id="@+id/top"
android:nextFocusUp="@+id/bottom"
... />
<Button android:id="@+id/bottom"
android:nextFocusDown="@+id/top"
... />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
<!-- 구현부분 --> >
<Button android:id="@+id/top"
android:nextFocusUp="@+id/bottom"
<!-- 구현부분 --> />
<Button android:id="@+id/bottom"
android:nextFocusDown="@+id/top"
<!-- 구현부분 --> />
</LinearLayout>
Context context = getApplicationContext(); CharSequence text = “Hello toast!”; int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration); toast.show();
Context context = getApplicationContext();
CharSequence text = "토스트 메시지 입니다.";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
Toast.makeText(context, text, duration).show();
Context context = getApplicationContext();
CharSequence text = "토스트로 통보하기 입니다.";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);
toast.show();
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:background="#DAAA"
>
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup) findViewById(R.id.toast_layout_root));
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.icon);
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("커스텀 토스트 완성!!!");
Toast toast = new Toast(getApplicationContext());
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);