2016-05-18 8 views
0

こんにちは私は新しいアプリケーションを開発するためにC#とXamarinを使い、このプラットフォームを使用して多くの問題に遭遇しました。 xamarinを使用してNavigationView内のメニュー項目をカスタマイズすることは可能ですか?私が見つけたのはvalid properties for the menu itemsです。 しかしこれに代え場合:Xamarin NavigationViewメニュー項目のカスタマイズ

<menu xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:id="@+id/itemOne" 
     android:title="Go to page one" /> 
    <item 
     android:id="@+id/itemTwo" 
     android:title="Go to page two" /> 
</menu> 

私はこれをしたい:

<menu xmlns:android="http://schemas.android.com/apk/res/android"> 
    <TextView></TextView> 
    <Button></Button> 
    <SomeOtherControlHere></SomeOtherControlHere> 
</menu> 

はxamarin使用して、それは可能ですか?私の他の選択肢は何ですか?

<menu xmlns:android="http://schemas.android.com/apk/res/android"> 
     <item 
      android:id="@+id/itemOne" 
      android:title="Go to page one" 
      android:fontFamily="MyCustomFontName Or MyPathToFonts" /> <-- NOT VALID 
</menu> 

また、私は全体のスタイルを適用する場合:さておき、私はXamarinのAPI年代は、たとえばメニュー項目のフォントを設定するには、XML内で直接カスタムTTFフォントを使用するカント、非常に制限されていることがわかったことから

メニュー項目コンテナカスタムフォントを使用することもできません。私たちが使用できるフォントは、組み込みのフォントだけです。

アクティビティ内の個々のメニュー項目(IMenuItem)への参照を取得しても、フォントファミリを設定するプロパティや関数はありません。

+0

どのようにNavigationViewを使うのですか? axmlのこの部分を表示できますか? –

答えて

0

より複雑なNavigationViewを定義することは可能です。子コントロールをNavigationView-Tagの中に置くだけです。たとえば、これはNavigationViewを使用してフッターを実装する方法です。

<android.support.design.widget.NavigationView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/navigation_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    local:headerLayout="@layout/drawer_header" 
    local:theme="@style/NavigationDrawerStyle" 
    local:menu="@menu/drawer_menu"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="bottom" 
     android:orientation="vertical"> 
     <TextView 
      android:id="@+id/empty_spacer" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:clickable="false" 
      android:text="" /> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="65dp" 
      android:background="@drawable/footer_small" 
      android:orientation="vertical" 
      android:weightSum="1" /> 
    </LinearLayout> 
</android.support.design.widget.NavigationView> 

例えばアイテムのTextSizeプロパティを変更するには、独自のスタイルを定義する必要があります。:子供には制限があなたにもボタンそうすることができますなどを制御はありません

<style name="NavigationDrawerStyle"> 
    <item name="android:textSize">24sp</item> 
    <!-- more properties --> 
</style> 

次に、NavigationViewに割り当てます。

0

これは、アイコンで始まり、次にメニューテキストで、最後は番号であるナビゲーションメニュー項目をフォーマットする方法です。それはGmailのアプリのように見えます。

OnCreateの

navigationView = FindViewById<NavigationView>(Resource.Id.wnl_nav_view); 

      //Add customize menu item style 
      IMenu menuNav = navigationView.Menu; 
      View view = View.Inflate(this, Resource.Layout._drawerMenuItemTemplate, null); 
      IMenuItem logoutItem = menuNav.FindItem(Resource.Id.nav_mail); 
      MenuItemCompat.SetActionView(logoutItem, view); 
      TextView txtNewNumber = view.FindViewById<TextView>(Resource.Id.txtNewNumber); 

_drawerMenuItemTemplate.axml

<?xml version="1.0" encoding="utf-8"?> 
 
<FrameLayout xmlns:card_view="http://schemas.android.com/apk/res-auto" 
 
    xmlns:android="http://schemas.android.com/apk/res/android" 
 
    android:layout_width="fill_parent" 
 
    android:layout_height="wrap_content"> 
 
    <TextView 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" 
 
     android:textColor="@color/primary_text" 
 
     android:text="3/30" 
 
     android:id="@+id/txtNewNumber" 
 
     android:layout_gravity="right" 
 
     android:fontFamily="@string/abc_font_family_display_2_material" 
 
     android:textSize="13sp" 
 
     android:textStyle="bold" 
 
     android:paddingRight="6dp" 
 
     android:layout_marginTop="14dp" /> 
 
</FrameLayout>

関連する問題