Hướng Dẫn Thay đổi Font Chữ Trong Android Studio
Có thể bạn quan tâm
Home Android Hướng dẫn thay đổi font chữ trong Android Studio
tiếp tục ta tạo thư mục fonts trong thư mục assets chúng ta vừa tạo xong. Sau đó coppy các loại fonts mà các bạn muốn sử dụng vào đó
B3. Thiết kế giao diện màn hình chính code của actiivity_main.xml như sau
B4. Code MainActivity.java
trong đoạn code trên các bạn chỉ cần chú ý 2 dòng code sau Typeface face = Typeface.createFromAsset(getAssets(), “fonts/FORTE.TTF”);edtContent.setTypeface(face); ở dòng đầu tiên, đó là chúng ta tiến hành load font trong thư mục assets/fontsdòng tiếp theo là chúng ta set fonts cho edittext của chúng ta. Cũng không quá khó hiểu đúng không ạ. Và sau đó run và được kết quả như mong muốn.
Tuesday, January 24, 2017
Hướng dẫn thay đổi font chữ trong Android Studio in Android published on January 24, 2017 leave a reply Ở bài hôm này mình sẽ hướng dẫn các bạn làm sao để có thể sử dụng nhiều loại font cho ứng dụng của mình trể nên đẹp và đỡ nhàm chán hơn.1. Giới thiệu về fonts trong Android
Font là tập hợp hoàn chỉnh các chữ cái, các dấu câu, các con số, và các ký tự đặc biệt, theo một kiểu loại, định dạng (thường hoặc đậm nét), hình dáng (thẳng hoặc nghiêng) và kích cỡ phù hợp và có thể phân biệt khác nhau. Thường thuật ngữ “typeface” được dùng không đúng để chỉ về kiểu loại.2. Demo hướng dẫn thay đổi fonts trong Android
Sau đây mình sẽ hướng dẫn các bạn làm 1 ví dụ để thay đổi được font chữ của 1 đoạn văn bản. Ví dụ của mình đơn giản là sẽ có 1 edittext cho phép người dùng nhập nội dung bất kỳ vào đó, và có 4 radiobutton cho phép người dùng chọn fonts mình mong muốn và khi đó font của đoạn văn bản cũng thay đổi theo. B1. Tạo Project mới có tên là FontsDemo B2.Tạo thư mục chứa fonts Đâu tiên các bạn tạo thư mục assets trong project của mình theo cách như sau.| 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <TextView android:textColor="#ff0264ff" android:layout_gravity="center" android:layout_marginTop="15dp" android:textStyle="bold" android:textSize="40sp" android:text="Font in Android" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <EditText android:gravity="top|left" android:id="@+id/edtContent" android:layout_marginTop="15dp" android:hint="Nhập văn bản..." android:textSize="20sp" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="2"/> <RadioGroup android:layout_gravity="bottom" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1"> <RadioButton android:id="@+id/rdoFont1" android:text="Font1" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1"/> <RadioButton android:id="@+id/rdoFont2" android:text="Font2" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1"/> <RadioButton android:id="@+id/rdoFont3" android:text="Font3" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1"/> <RadioButton android:id="@+id/rdoFont4" android:text="Font4" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1"/> </RadioGroup> </LinearLayout> |
| 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | packagedevpro.com.fontdemo; import android.app.Activity; import android.graphics.Typeface; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.EditText; import android.widget.RadioButton; publicclassMainActivityextendsActivity{ EditText edtContent; RadioButton rdoFont1,rdoFont3,rdoFont2,rdoFont4; Typeface face; @Override protectedvoidonCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); edtContent=(EditText)findViewById(R.id.edtContent); rdoFont1=(RadioButton)findViewById(R.id.rdoFont1); rdoFont2=(RadioButton)findViewById(R.id.rdoFont2); rdoFont3=(RadioButton)findViewById(R.id.rdoFont3); rdoFont4=(RadioButton)findViewById(R.id.rdoFont4); rdoFont1.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(View view){ //Thiết lập font để sử dụng từ assets face=Typeface.createFromAsset(getAssets(),"fonts/FORTE.TTF"); //Set font cho edittext của các bạn. edtContent.setTypeface(face); } }); rdoFont2.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(View view){ face=Typeface.createFromAsset(getAssets(),"fonts/GiddyupStd.otf"); edtContent.setTypeface(face); } }); rdoFont3.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(View view){ face=Typeface.createFromAsset(getAssets(),"fonts/GIGI.TTF"); edtContent.setTypeface(face); } }); rdoFont4.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(View view){ face=Typeface.createFromAsset(getAssets(),"fonts/VNARIAL.TTF"); edtContent.setTypeface(face); } }); } } |
- Tweet
- Share
- Share
- Share
- Share
post written by: f7deat
0 comments:
Xem Nhiều
- Xây dựng Web Service dùng API RESTful Service(phần 1) Ở các bài trước (.Net Web Service & KSOAP API) Tui có trình bày về cách tạo và sử dụng Web Service bằng .asmx, nó có một số hạn chế nhấ...
- Thế giới của Sophie - Tiểu thuyết về lịch sử Triết học Sophie Amundsen từ trường về. Ban đầu, cô đi cùng Jorunn một đoạn. Cả hai đã nói về người máy. Theo Jorunn, bộ óc con người là một cỗ máy đi...
- [Tóm tắt sách] Đừng làm việc chăm chỉ hãy làm việc thông minh Chuẩn mực trong môi trường làm việc hiện đại là nhiều hơn, lớn hơn và nhanh hơn. Chúng ta có nhiều khách hàng để làm vừa lòng, nhiều thư điệ...
- Án mạng trên chuyến tàu tốc hành phương Đông: Hercule Poirot bao che tội ác Án mạng trong phòng kín luôn là chủ đề được các tiểu thuyết gia trinh thám ưa thích. Bởi, không chỉ thể hiện bút lực của tác giả trong xây d...
Social Media Icons
Labels Cloud
ASP.NET Android MMO JavaScript Wordpress Unity3D Youtube PHP SEO JavaThông Tin
Get more nice stuff in your inbox
Nhận nội dung mới nhất từ chúng tôi
Labels
.NET Affiliate After Effect Android Angular API 2 AR ASP.NET ASP.NET MVC Asset Bảo mật Bootstrap C# C++ CNTT CSS Domain Excel Facebook Git Guide Game History Hội họa Hosting HTML IELTS IIS Interview Java JavaScript Khám phá Khóa học Lập trình Lịch sử Microsoft Word MMO MVC Nhân vật - Sự kiện PHP React Resource Sách SEO Source Control SQL Tài liệu Thủ thuật Tiếng Anh Cơ Bản TOEIC Tool Trick Tutorials Twig TypeScript Unity3D Web API Website Windows Form Wordpress YoutubeTừ khóa » Chỉnh Font Chữ Trong Android Studio
-
Phông Chữ ở định Dạng XML | Android Developers
-
Làm Việc Với Custom Font Trong Android O - Viblo
-
2 Cách Tốt Nhất để Tuỳ Chỉnh Phông Chữ Trong Android - Viblo
-
Android Studio - Đổi Font Và Size Chữ Theo ý Muốn - YouTube
-
Làm Cách Nào để Thay đổi Phông Chữ Trên TextView? - HelpEx
-
Cách Sử Dụng Phông Chữ Tùy Chỉnh Trong Một Dự án được Viết Trong ...
-
[Android] Tạo Fonts Cho Text Trong Android - Cách Học
-
Mẹo Nhỏ: Làm Việc Với Phông Chữ Tuỳ Biến Trong Android O
-
TextView Trong Lập Trình Android Hiện Thị Text, HTML, SpannableString
-
Định Cỡ Phông Chữ Android Studio Editor
-
Bài 19 - Fonts Text In Android
-
Android Studio: Căn Chỉnh Background, Font, Màu Chữ Cho Các Thành ...
-
Làm Cách Nào để Tăng Kích Thước Phông Chữ Trong Android Studio?