Android

안드로이드 강의 정리 (홍드로이드)

  TextView EditText & Button Intent 화면전환       안드로이드 앱 만들기 #0 (안드로이드 스튜디오 설치 및 환경설정)   구글에서 안드로이도 스튜디오 검색   https://developer.android.com/studio?hl=ko     안드로이드 앱 만들기 #1 (TextView)     안드로이드 앱 만들기 #2 (EditText & Button)     안드로이드 앱 만들기 #3 (Intent 화면전환)   activity_main.xml   <LinearLayout android:layout_width=”match_parent” android:layout_height=”match_parent”> <EditText android:id=”@+id/et_test” android:layout_width=”200dp” android:layout_height=”wrap_content” /> <Button android:id=”@+id/btn_move” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”이동”/> </LinearLayout>   activity_sub.xml   <LinearLayout android:layout_width=”match_parent” android:layout_height=”match_parent”> <TextView android:id=”@+id/tv_sub” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:textSize=”30sp” android:text=”서브 액티비티 도착”/> </LinearLayout>     MainActivity.java   public class MainActivity extends…

Read More
Android

될 때까지 안드로이드 정리 (오준석의 생존코딩) 1

  2장 첫 번째 앱 만들기, 3장 뷰와 뷰그룹 5장 레이아웃: 화면에 뷰를 수 놓는 방법 6장 안드로이드는 액티비티로부터 7장 인텐트와 인텐트 필터 8장 UpNavigation과 메뉴 구현하기 9장 웹뷰 웹 페이지 표기하기 10장 화면 제약을 극복하는 방법 – ListView 11장 기기에 데이터 저장하기 SharedPreference 12장 액티비티 생명주기 13장 프래그먼트     될 때까지 안드로이드 #1 [2장 첫 번째 앱 만들기, 3장 뷰와 뷰그룹]   activity_main.xml   <LinearLayout android:layout_width=”match_parent” android:layout_height=”match_parent”> <TextView android:id=”@+id/edit_message” android:layout_width=”0dp” android:layout_height=”wrap_content” android:layout_weight=”1″ android:hint=”@string/edit_message” /> // 나중에 국제화를 위해서 string 값을 리소스로 빼기 // (2가지 방법: values/strings.xml 파일에 직접…

Read More
Android

Check Box

    chk_red.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { } }); chk_blue.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(((CompoundButton) view).isChecked()){ Log.d(TAG, “Checked”); } else { Log.d(TAG, “Un-Checked”); } } }); https://stackoverflow.com/questions/8386832/android-checkbox-listener         <androidx.constraintlayout.widget.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” tools:context=”.CheckboxActivity”> <TextView android:id=”@+id/tv_result” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginTop=”32dp” android:text=”결과 텍스트” android:textSize=”36sp” app:layout_constraintLeft_toLeftOf=”parent” app:layout_constraintRight_toRightOf=”parent” app:layout_constraintTop_toBottomOf=”@+id/btn_result” /> <CheckBox android:id=”@+id/chk_red” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginTop=”100dp” android:text=”빨강” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”parent” /> <CheckBox android:id=”@+id/chk_blue” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”파랑” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintHorizontal_bias=”0.498″ app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toBottomOf=”@+id/chk_red” /> <CheckBox android:id=”@+id/chk_green” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”초록” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintHorizontal_bias=”0.498″ app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toBottomOf=”@+id/chk_blue” />…

Read More
Android

Radio Button

          activity_main.xml   <androidx.constraintlayout.widget.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” tools:context=”.MainActivity”> <RadioGroup android:id=”@+id/rg_gender” android:layout_width=”wrap_content” android:layout_height=”wrap_content” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”parent” > <RadioButton android:id=”@+id/rb_man” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:text=”남자” /> <RadioButton android:id=”@+id/rb_woman” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:text=”여자” /> </RadioGroup> <Button android:id=”@+id/btn_result” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginTop=”50dp” android:text=”결과 버튼” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toBottomOf=”@+id/rg_gender” /> </androidx.constraintlayout.widget.ConstraintLayout>       MainActivity.java   public class MainActivity extends AppCompatActivity { private RadioGroup rg_gender; private RadioButton rb_man, rb_woman; private Button btn_result; private String str_result; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rg_gender = findViewById(R.id.rg_gender); // 라디오 버튼들을 담고있는 그룹 rb_man =…

Read More
Android

ViewPager

    Migrate from ViewPager to ViewPager2 https://developer.android.com/training/animation/vp2-migration   ViewPager2 https://developer.android.com/reference/androidx/viewpager2/widget/ViewPager2   FragmentStateAdapter https://developer.android.com/reference/androidx/viewpager2/adapter/FragmentStateAdapter     Frag1.java, Frag2.java, Frag3.java   public class Frag1 extends Fragment { private View view; public static Fragment newInstance() { return new Frag1(); } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment1, container, false); } }         ViewPagerAdapter.java   public class ViewPagerAdapter extends FragmentPagerAdapter { public ViewPagerAdapter(@NonNull FragmentManager fm, int behavior) { super(fm, behavior); } @NonNull @Override public Fragment getItem(int position) { switch (position) {…

Read More
Android

WebView

  <uses-permission android:name=“android.permission.INTERNET“/>   // https 가 아닌 http 는 보안 문제로 접근이 되지 않는다. 그걸 풀어준다. android:usesCleartextTraffic=”true” (AndroidManifest.xml -> application)     <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:orientation=”vertical” android:layout_height=”match_parent”> <WebView android:id=”@+id/webView” android:layout_width=”match_parent” android:layout_height=”match_parent” /> </LinearLayout>     public class SettingsActivity extends AppCompatActivity { private WebView webView; private String url = “https://www.naver.com”; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.settings_activity); webView = (WebView) findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); // 자바스크립트 기본값은 false webView.loadUrl(url); webView.setWebChromeClient(new WebChromeClient()); webView.setWebViewClient(new WebViewClientClass()); // setWebViewClient 가 주어지지 않으면 시스템 브라우저로 보여짐 } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if…

Read More
Android

VideoView

    <uses-permission android:name=”android.permission.INTERNET” /> android:screenOrientation=”landscape” android:theme=”@style/Theme.AppCompat.NoActionBar”     <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” tools:context=”.MainActivity”> <VideoView android:id=”@+id/videoView” android:layout_alignParentTop=”true” android:layout_alignParentBottom=”true” android:layout_alignParentLeft=”true” android:layout_alignParentRight=”true” android:layout_width=”fill_parent” android:layout_height=”fill_parent”> </VideoView> </RelativeLayout>         public class MainActivity extends AppCompatActivity { private VideoView videoView; private MediaController mediaController; private String videoURL = “영상 주소”; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); videoView = findViewById(R.id.videoView); mediaController = new MediaController(this); mediaController.setAnchorView(videoView); Uri uri = Uri.parse(videoURL); videoView.setMediaController(mediaController); videoView.setVideoURI(uri); videoView.start(); } }           안드로이드 앱 만들기 #32 동영상 풀화면 재생 (VideoView) https://www.youtube.com/watch?v=OBY1jDXF8QE  

Read More