我添加了一个新字体,与第一个一起使用

时间:2014-04-19 23:02:10

标签: java android xml eclipse

我添加了一个名为cgib.ttf的新字体,我去了MainActivity.java添加了2个titleTexts 这是activity_main.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#1d72c3"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/title"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:text="@string/titleText"
            android:textColor="#ffffff"
            android:textSize="55sp" />
        <TextView
            android:id="@+id/kark"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:text="@string/titleText2"
            android:textColor="#ffffff"
            android:textSize="30sp" />
    </LinearLayout>

这是MainActivity.java

package com.sa.damas;
import android.R;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initTypeFace();
        }
    private void initTypeFace() {
        Typeface cgib = Typeface.createFromAsset(getAssets(), "fonts/cgib.ttf");


        TextView titleText=(TextView) findViewById(R.id.title);
        titleText.setTypeface(cgib);


        TextView titleText2=(TextView) findViewById(R.id.kark);
        titleText2.setTypeface(cgib);
    }
}

标题是固定的,第二个(kark)无法在列表中找到

1 个答案:

答案 0 :(得分:0)

import android.R;替换为import R;

android.R包含系统资源,而不是您项目的资源