안드로이드 스튜디오

toast: 기본형 Toast --> 하단 toast

toast2: 레이아웃 적용한 Toast --> 중단 COLORTOAST


추가로 toast 누를때마다 숫자 증가해서 보여주게 설정






public class MainActivity extends AppCompatActivity {

public int number = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


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

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Toast toast = Toast.makeText(getApplicationContext(), "Toast test",Toast.LENGTH_LONG);


toast.setGravity(Gravity.TOP | Gravity.LEFT, 200,500);

toast.setText("tttt");

toast.show();



toast.setText("Toast" + number);
number++;


}
});

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

button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

LayoutInflater inflater = getLayoutInflater();

View layout = inflater.inflate(R.layout.toastborder, (ViewGroup)findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("shape Toast");

Toast toast = new Toast(getApplicationContext());

toast.setGravity(Gravity.CENTER, 0,-200);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();



}
});


}




}



스마트폰의 키 (화면하단 3개 버튼, 좌우, 전원 ...) 처리




@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){
Toast.makeText(this, "BACK button",Toast.LENGTH_LONG).show();


}
return true;
//return super.onKeyDown(keyCode, event);
}

키 리스트


a - z-> 29 - 54

"0" - "9"-> 7 - 16

BACK BUTTON - 4, MENU BUTTON - 82

UP-19, DOWN-20, LEFT-21, RIGHT-22

SELECT (MIDDLE) BUTTON - 23

SPACE - 62, SHIFT - 59, ENTER - 66, BACKSPACE - 67

android:state_pressed="true" // 눌렸을 때 반응

Drawable에 아래 코드 입력
<item

android:state_pressed="true"
android:drawable="@drawable/img1"
/>
<item
android:drawable="@drawable/img2"
/>




[안드로이드] 스크롤뷰

2019. 1. 11. 00:15

ScrollView 태그 사용하면 내부 뷰의 사이즈가 넘칠 경우 스크롤이 가능하다.

ScrollView --> LinearLayout --> View 순으로 위계 정해지는듯.



귀찮아서 스샷은 패스.


<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="500dp"
android:text="이건긴글입니다매우긴글\n이건긴글입니다매우긴글\n이건긴글입니다매우긴글\n이건긴글입니다매우긴글\n이건긴글입니다매우긴글\n이건긴글입니다매우긴글\n이건긴글입니다매우긴글\n이건긴글입니다매우긴글\n"
/>
</LinearLayout>
</ScrollView>
</TableRow>


layer-list: shape를 중첩시켜주는 태그

shape: 간단한 스케치가 가능한 layout 설정

gradient: shape 내 gradient 색상 지정




<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item>
<shape android:shape="rectangle">
<gradient
android:startColor="#0000ff"
android:endColor="#ff0000"
android:angle="45"
android:centerColor="#00ff00"
/>
<size
android:height="10dp"
android:width="10dp"
/>

<corners
android:radius="1dp"
/>

</shape>

</item>

<item>

<shape android:shape="oval">
<size
android:width="10dp"
android:height="10dp"
/>

<gradient
android:startColor="#ff0000"
android:endColor="#0000ff"
android:angle="135"
android:centerColor="#00ff00"
/>

</shape>

</item>



</layer-list>


+ Recent posts