【发布时间】:2016-08-08 03:40:08
【问题描述】:
我在我的应用程序中使用自定义字体,问题是,它适用于小于 Lollipop 和大于 lolliop 的 android 版本,但在 Lollipop 上它只是空白
请查看附件中的代码和截图
SelectionPage.java
package com.execube.volantis.views;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import com.execube.volantis.R;
import com.execube.volantis.receiver.customHandler;
import com.flaviofaria.kenburnsview.KenBurnsView;
import com.flaviofaria.kenburnsview.RandomTransitionGenerator;
import com.pushbots.push.Pushbots;
import io.fabric.sdk.android.Fabric;
public class SelectionPage extends AppCompatActivity {
private Button mEventsButton;
private Button mAlertsButton;
private Button mAboutButton;
private Button mDirectionsButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics());
setContentView(R.layout.selection_page);
Pushbots.sharedInstance().init(this);
Pushbots.sharedInstance().setCustomHandler(customHandler.class);
mEventsButton=(Button)findViewById(R.id.events_button);
mAboutButton=(Button)findViewById(R.id.about_button);
mAlertsButton=(Button)findViewById(R.id.alerts_button);
mDirectionsButton=(Button)findViewById(R.id.directions_button);
Typeface gothamRoundedMedium= Typeface.createFromAsset(getAssets(),"fonts/Gotham-Rounded-Medium.ttf");
mEventsButton.setTypeface(gothamRoundedMedium);
mAboutButton.setTypeface(gothamRoundedMedium);
mDirectionsButton.setTypeface(gothamRoundedMedium);
mAlertsButton.setTypeface(gothamRoundedMedium);
mEventsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent= new Intent(SelectionPage.this,EventActivity.class);
startActivity(intent);
}
});
mDirectionsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String geoUri = "http://maps.google.com/maps?q=loc:" + "12.9021902" + "," + "77.518582" + " (" + "RNS Institute Of Technlogy" + ")";
Intent intent= new Intent(Intent.ACTION_VIEW, Uri.parse(geoUri));
startActivity(intent);
}
});
mAlertsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent= new Intent(SelectionPage.this,AlertsActivity.class);
startActivity(intent);
}
});
mAboutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent= new Intent(SelectionPage.this,AboutActivity.class);
startActivity(intent);
}
});
}
}
按钮使用自定义字体。
只有在android版本不等于Lollipop的情况下,有没有办法设置自定义字体?
这里是 Marshmallow API 23
这里是 Lollipop API 21
【问题讨论】:
标签: java android xml android-5.0-lollipop android-custom-view