私は2つのアクティビティ(実際には4つだけですが現在は2つの問題あり)、主なアクティビティとフォント変更アクティビティを持っています。メインアクティビティは、ユーザが入力したテキストをintent
とstartActivityForResult
を使用してフォント変更アクティビティに送信します。フォント変更アクティビティ内で、ユーザーはテキストのフォントを期待どおりに変更できます。私がしようとしているのは、ユーザーがフォントを変更し、テキストと新しいフォントを主なアクティビティに送り返した後です。しかし、私はこれを行う方法がわかりません。私はbundle
のようなものを使うことを考えていますが、私は立ち往生しています。誰かが私を助けることができれば、それは大変に感謝されるでしょうインテントにフォントを追加して別のアクティビティに送信
は、ここに私の(関連)主な活動コードがあります:これはTextViewにからfontActivityにあなたの文字列を取得します
public class Main4Activity extends AppCompatActivity
{
TextView user_font_text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main4);
user_font_text = (TextView) findViewById(R.id.user_font_text);
}
public void boldText(View view)
{
Typeface custom_font = getResources().getFont(R.font.avenir_next_bold);
user_font_text.setTypeface(custom_font);
}
public void italicText(View view)
{
Typeface custom_font = getResources().getFont(R.font.avenir_next_italic);
user_font_text.setTypeface(custom_font);
}
public void regularText(View view)
{
Typeface custom_font = getResources().getFont(R.font.avenir_next_regular);
user_font_text.setTypeface(custom_font);
}
public void thinText(View view)
{
Typeface custom_font = getResources().getFont(R.font.avenir_next_thin);
user_font_text.setTypeface(custom_font);
}
public void OK(View view)
{
//The intent and/or bundle would go here but I don't know what to do
}
}
フォントを渡す必要はなく、 'R.font.some_font'からIntegerを渡すだけです! – Xenolion