0
のMenuItem
のタイトルにはTextView
を取得できますか? (私は、フォントを変更したい)Androidのサポートライブラリ - タイトルを取得するNavigationViewからのテキストビュー
drawer_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item
android:id="@+id/cards"
android:icon="@drawable/ic_menu_cards"
android:clickable="false"
android:title="Cards"
app:showAsAction="always"/>
<item
android:id="@+id/waiter"
android:icon="@drawable/ic_menu_waiter"
android:clickable="false"
android:title="Timer Mode"
app:showAsAction="always"/>
<item
android:id="@+id/settings"
android:icon="@drawable/ic_menu_settings"
android:title="Settings"
app:showAsAction="always"/>
<item
android:id="@+id/purchase"
android:icon="@drawable/ic_menu_purchase"
android:clickable="false"
android:title="Purchase"
app:showAsAction="always"/>
<item
android:id="@+id/feedback"
android:icon="@drawable/ic_menu_feedback"
android:clickable="false"
android:title="Feedback"
app:showAsAction="always"/>
</group>
</menu>
そして、私のレイアウト:私はMenuItem
動作するはずTextView
になく、鋳造他のいくつかの例を見てきました
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- Removed for simplicity -->
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:theme="@style/NavigationDrawer"
app:headerLayout="@layout/navigation_view_header"
app:itemTextColor="@color/white"
app:menu="@menu/drawer_menu" />
</android.support.v4.widget.DrawerLayout>
私nullの場合はnullを返します。
TextView title = (TextView) navigationView.getMenu().getItem(0) <-- TextView becomes null
フォントを操作できるようにタイトルにアクセスするにはどうすればよいですか?
詳しい背景情報:
私は通常のデータ連結を使用してフォントを設定していますが、Androidのサポートライブラリのコンポーネントのために、これは私が手動でのTextViewにアクセスし、このようにそれを設定する必要がありそう動作しません:
textView.setTypeface(FontCache.getInstance(textView.getContext()).get("lato_regular"));
:TypefaceSpanを拡張
ヘルパークラス:
メソッドは次のようになりますプログラムでフォントを作成するか、 'TextView'を取得します。 'NavigationView'については、ほとんど全ての側面をカスタマイズしてカスタマイズすることができます。あなたの場合、 'itemTextAppearance'属性にスタイルを割り当てるだけです。 –
私はフォントを設定するためのデータバインディングを使用していて、書道のようなものを使う気にはならないので、不幸にもそれは不可能です。これを見てください:https://github.com/lisawray/fontbinding – nilsi