我在" Logo Maker"项目....现在我' m面临将字体从一个活动发送到另一个活动的问题
这就是我的尝试:
AddTextActivity:
tt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
var="font1.ttf";
tf = Typeface.createFromAsset(AddTextActivity.this.getAssets(), "font1.ttf");
edtText.setTypeface(tf);
}
});
Intent intent=new Intent();
intent.putExtra("color",fontColor);
intent.putExtra("msg",message);
intent.putExtra("style",var);
setResult(2,intent);
finish();
LogoEditorActivity:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// check if the request code is same as what is passed here it is 2
if(requestCode==2)
{
String color=data.getStringExtra("color"); //this works fine
String message=data.getStringExtra("msg"); //this works fine also
String style=data.getStringExtra("style");
Log.e("style",style);
tf = Typeface.createFromAsset(LogoEditorActivity.this.getAssets(),style);
sticker = new TextSticker(this);
sticker.setDrawable(ContextCompat.getDrawable(getApplicationContext(),
R.drawable.sticker_transparent_background));
sticker.setText(message);
sticker.setTextColor(Color.parseColor(color));
sticker.setTextAlign(Layout.Alignment.ALIGN_CENTER);
sticker.resizeText();
sticker.setTypeface(tf); //this not working
stickerView.addSticker(sticker);
}
}
只需将Font TypeFace设置为sticker.setTypeface()....