Skip to content

Instantly share code, notes, and snippets.

@benznest
Last active September 22, 2016 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benznest/fc13fd5299797c0311bf28eefe36b577 to your computer and use it in GitHub Desktop.
Save benznest/fc13fd5299797c0311bf28eefe36b577 to your computer and use it in GitHub Desktop.
Test custom font library with Calligraphy.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context="com.benzneststudios.mycustomfont.MainActivity"
android:padding="16dp">
<TextView
android:id="@+id/tv_hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!!"
android:layout_centerHorizontal="true"
android:textSize="36sp"/>
<TextView
android:text="I am developer."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_hello"
android:textSize="36dp"
android:layout_centerHorizontal="true"
android:textAppearance="@style/MyFont"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.benzneststudios.mycustomfont">
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
package com.benzneststudios.mycustomfont;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showDialog();
}
private void showDialog() {
new AlertDialog.Builder(MainActivity.this)
.setTitle("Delete this?")
.setMessage("Are you sure you want to delete this?")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(base));
}
}
package com.benzneststudios.mycustomfont;
import android.app.Application;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
/**
* Created by benznest on 12-Sep-16.
*/
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
initFont();
}
private void initFont() {
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/junegull.ttf")
.setFontAttrId(R.attr.fontPath)
.build()
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment