-1
私はスイッチが Actionbar to Toolbarからです!よりよいデザインのためツールバーの変更Textviewタイトル
私は
私はこれでテストイストを持っているのTextViewと私のツールバー のフォントと
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
TextView toolbarTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/NewFont.ttf");
toolbarTitle.setTypeface(myTypeface);
今すぐすべての設定フラグメントページに同じテキストの設定にある、このコードを変更する必要があり
private void setTitleText(String Title) {
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
TextView toolbarTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/NewFont.ttf");
toolbarTitle.setText(Title);
toolbarTitle.setTypeface(myTypeface);
}
そして、ここで断片の種類別セグメントの1
public static class GeneralPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_general);
//with this i call the title change
setTitleText(R.string.pref_header_general);
setHasOptionsMenu(true);
// Bind the summaries of EditText/List/Dialog/Ringtone preferences
// to their values. When their values change, their summaries are
// updated to reflect the new value, per the Android Design
// guidelines.
bindPreferenceSummaryToValue(findPreference("example_text"));
bindPreferenceSummaryToValue(findPreference("example_list"));
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
startActivity(new Intent(getActivity(), SettingsActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
}
と、この私がこの
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
TextView toolbarTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/NewFont.ttf");
toolbarTitle.setTypeface(myTypeface);
に変更する必要があり、私は簡単な方法
を発見した
Non-static method 'setTitleText(java.lang.String)' cannot be referenced from a static context
編集
このエラーメッセージを持って働いていません
TextView toolbarTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/NewFont.ttf");
toolbarTitle.setText(toolbar.getTitle());
toolbarTitle.setTypeface(myTypeface);
getSupportActionBar().setDisplayShowTitleEnabled(false);
そして今、すべて正常に動作しますが
これは、テストはこれは私が静的 このフラグメント内部クラスは静的である必要があります削除すると、私のエラーメッセージです(com.test.beta自己 でお願いしない取り組んでいます。 SettingsActivity.GeneralPreferenceFragment) –
なぜフラグメントでsetTitleTextメソッドを呼び出しましたか?私はあなたのMainActivityでそれを呼び出すことをお勧めします –
呼び出されたフラグメントが分かっているはずなので、私はそれを呼び出します。アンドロイドスタジオで設定テンプレートを見ることができます。私はテキストビューを使用しているので、残念ながらツールバーのタイトル自体は変更されません。 –