DatePicker Dialog trong android java

Bài viết này sử dụng DatePicker dạng Dialog khác với DatePicker gắn trên layout https://zezo.dev/view/datepicker-trong-android-java Trên layout sẽ thêm 1 textview, khi bấm vào textview thì hiển thị dialog chọn ngày tháng, khi chọn ngày tháng trên dialog thì sẽ gán lại ngày tháng vào textview Bước 1: Thêm textview vào layout của activity <TextView android:id=”@+id/tv01″ […]

TimePickerDialog trong android java

Demo sử dụng TimePickerDialog để chọn thời gian trong android java Bạn nên tạo 1 Project mới để thử nghiệm Bước 1: Trong layout bạn tạo 1 cái textview để chọn thời gian <TextView android:id=”@+id/tv_time” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Thời gian” android:textSize=”30dp” android:textColor=”#FF5722″ android:layout_margin=”30dp” /> Bước 2: Thực hiện viết code java theo thứ tự sau TextView tv […]

Tạo đồng hồ đếm ngược thời gian trong android java

Bước 1: Tạo 1 project mới và tạo 1 textview trong layout activity <TextView android:id=”@+id/tv01″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” /> Bạn tự căn chỉnh textview cho phù hợp Bước 2: Trong code java của activity, bạn viết code sau để thực hiện đếm ngược TextView tv01 =findViewById(R.id.tv01); // ánh xạ view // tạo mới 1 đối tượng […]

Tạo Toast tùy chỉnh trong android java

Bước 1: Tạo 1 file layout cho cái Toast Chú ý đặt id cho thẻ LinearLayout là toast_root_layout còn các view con cái nào muốn gán giá trị thì đặt ID <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”horizontal” android:layout_width=”match_parent” android:layout_height=”match_parent” android:background=”#FFEB3B” android:id=”@+id/toast_root_layout” android:padding=”30dp” > <ImageView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:src=”@android:drawable/ic_delete”/> <TextView android:id=”@+id/tv_toast_content” android:layout_width=”0dp” android:layout_weight=”1″ android:layout_height=”wrap_content” android:text=”Nội dung toast” android:textColor=”#FF5722″ android:textSize=”20dp”/> […]

Hướng dẫn lấy định vị (GPS)

Tài liệu tham khảo định vị: https://developer.android.com/training/location Bước 1: Copy permission cho vào Mainifest: <uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION” /> <uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” /> <uses-permission android:name=”android.permission.INTERNET” /> Bước 2: Khai báo đối tượng để nhận trạng thái khi hộp thoại cấp quyền đóng lại: Code này để ở phạm vi class, để bên ngoài hàm onCreate nhé. ActivityResultLauncher<String[]> locationPermissionRequest = registerForActivityResult(new ActivityResultContracts […]

Hướng dẫn thực hành XmlPullParser đọc dữ liệu từ file xml trong android

Bước 1: Tạo project mới, tạo file xml dữ liệu để thực hành – Sau khi tạo project mới, bạn chuyển chế độ view thư mục về dạng Project Bước 2: Soạn nội dung file xml dữ liệu <?xml version=”1.0″ encoding=”utf-8″ ?> <products> <product> <name>Điện thoại</name> <price>300000</price> </product> <product> <name>Máy tính</name> <price>100000</price> </product> <product> <name>Tivi</name> […]

Hướng dẫn lấy nội dung Rss bằng XmlPullParser trong android

1. Phần chuẩn bị – Tạo 1 project mới hoàn toàn – Link đọc RSS: Thực hành với https://vnexpress.net/rss/cuoi.rss – Để chạy được cần khai báo trong manifest của ứng dụng có sử dụng quyền truy cập Internet: 2. Phân tích cấu trúc của RSS Bạn vào địa chỉ trang Rss ở trên, sau đó hãy kích […]

Code chuyển đổi ngày tháng trong android java

Chuyển đổi định dạng ngày tháng // lấy ngày tháng hiện tại của hệ thống Date objDate = new Date(System.currentTimeMillis()); // có đối tượng ngày tháng hiện tại // muốn hiển thị định dạng nào thì dùng đối tượng format để điều chỉnh // một số ký hiệu định dạng: ngày : dd, tháng: MM, […]

Tạo ứng dụng nghe nhạc đơn giản trong android java với MediaPlayer

Phần 1: Tạo media player với việc play file nhạc online Bước 1: Khai báo quyền sử dụng trong Mainifest <uses-permission android:name=”android.permission.INTERNET”/> Bước 2: Tạo layout có một số thành phần như thanh tiến trình, nút play, nút pause <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout 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” android:orientation=”vertical” > <ProgressBar android:id=”@+id/musicBar” style=”@style/Widget.AppCompat.ProgressBar.Horizontal” android:layout_width=”match_parent” […]

Tạo hiệu ứng trong ứng dụng Android – Animation

Animation trong android giúp bạn có thể xây dựng ứng dụng game, hoặc tạo các hiệu ứng sinh động cho ứng dụng giúp người dùng đỡ cảm thấy nhàm chán khi sử dụng ứng dụng. Android cung cấp các cách tạo hiệu ứng cho ứng dụng: –  Object Animator : Tạo đối tượng hiệu ứng […]