Hello everyone today Android example will introduce you a very nice How to change EditText font Android, to accomplish that problem, please follow the steps below.
Step 1. Create layout activity_main.xml
Step 1. Create layout activity_main.xml
<RelativeLayoutStep 2. Create a class MainActivity.class
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MainActivity"
android:background="#e9e6cb"
>
<EditText
android:id="@+id/et"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Default font family"
/>
<EditText
android:id="@+id/et2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Sans serif thin font"
android:padding="10dp"
android:fontFamily="sans-serif-thin"
android:layout_below="@+id/et"
/>
<EditText
android:id="@+id/et3"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_below="@+id/et2"
/>
</RelativeLayout>
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText et = (EditText) findViewById(R.id.et);
EditText et2 = (EditText) findViewById(R.id.et2);
EditText et3 = (EditText) findViewById(R.id.et3);
et3.setTypeface(Typeface.MONOSPACE);
et3.setText("Monospace font");
}
}
No comments:
Post a Comment