2016-04-07 11 views
0

私はGroupSectionオブジェクトのリストを示すナビゲーションドロワーを持っているAndroidプロジェクトに取り組んでいます。すべてのGroupSectionオブジェクトにはセクションアイコンが含まれています。引き出しアイコンは、TypedArrayといくつかのアンドロイド固有の構文によって決定され、リソースを取得します。私はそれをフォントのすばらしいアイコンに置き換えたいと思っています。各groupSectionオブジェクトには、アイコン文字列を返すgetter groupSection.getSectionIcon();があります。私はString.xmlにアイコンを追加し、アセットディレクトリにfontawesome-webfont.ttfを持っています。Android:ナビゲーションの引き出しアイコンをフォントのすばらしいアイコン(アイコンを使用可能)に置き換える方法

入力済みの配列をfont-awesomeアイコンで置き換える方法を知ることはできません。私はfindViewByID(R.id.awesome_icon).getId()といくつかの他の可能性を試しました。ありがとうございました。

コード:string.xmlをの

public void set(List<RestSection> restSectionList, TypedArray navMenuIcons, Long groupId, 
        int canvasid, int sectionId) { 
// Below are default icons 
    navMenuIcons = getResources() 
       .obtainTypedArray(R.array.nav_drawer_icons); 
    for (RestSection restSection : restSectionList) { 

// As you can see I am accessing the icons with there resource id. 
      navDrawerItems.add(new DrawerModel(restSection.getMsectionname(), 
        navMenuIcons.getResourceId(0, -1), restSection.getMsectionid())); 
     } 

サンプル:私は直接ゲッターとアイコンの文字列を取得しますが、設定することができますforループのように、それはどこの問題の嘘

<string name="pinterest">&#xf0d2;</string> 
    <string name="pinterest_square">&#xf0d3;</string> 
    <string name="google_plus_square">&#xf0d4;</string> 
    <string name="google_plus">&#xf0d5;</string> 
    <string name="money">&#xf0d6;</string> 
    <string name="caret_down">&#xf0d7;</string> 
    <string name="caret_up">&#xf0d8;</string> 
    <string name="caret_left">&#xf0d9;</string> 
    <string name="caret_right">&#xf0da;</string> 
    <string name="columns">&#xf0db;</string> 

ある

。どんな助けもいいだろう。ありがとうございました。 :-)

更新

私は手動で設定します以下のコードを試してみましたが、私は同様にそのためのエラーを取得する:

Unable to find resource: 2131165836 
android.content.res.Resources$NotFoundException: File  from drawable resource ID #0x7f07028c 
    at android.content.res.Resources.loadDrawableForCookie(Resources.java:2640) 
at android.content.res.Resources.loadDrawable(Resources.java:2540) 
at android.content.res.Resources.getDrawable(Resources.java:806) 
at android.content.Context.getDrawable(Context.java:458) 
at android.widget.ImageView.resolveUri(ImageView.java:811) 
at android.widget.ImageView.setImageResource(ImageView.java:418) 

コード:

for (RestSection restSection : restSectionList) { 
      if (restSection.getSectionIcon() != null) { 
       DrawerModel drawerModel = new DrawerModel(); 
       drawerModel.setTitle(restSection.getMsectionname()); 
       drawerModel.setId(restSection.getMsectionid()); 
       drawerModel.setIcon(R.string.try_icon); 

       navDrawerItems.add(drawerModel); 
      } else { 
       navDrawerItems.add(new DrawerModel(restSection.getMsectionname(), 
         navMenuIcons.getResourceId(0, -1), restSection.getMsectionid())); 
      } 
     } 
+0

は、なぜあなたはちょうどここに同等のフォント素晴らしいPNGアイコンをダウンロードすることができません:http://www.flaticon.com/packs/font-awesome –

答えて

1

素晴らしいフォントはテキストです。だからアイコンとしてそれらを使いたい場合は、それらをdrawableに変換する必要があります。 https://stackoverflow.com/a/8831182/3206226

+0

ありがとう

あなたはこのTextDrawable例を使用することができます。あなたはこの特定の問題にどのように私がそれを使うことができるかについて詳しく説明できますか?また、私はいくつかの新しいコードを試して、それを投稿しました。親切にチェックできますか?ありがとうございました。 :-) –

+0

DrawerModelとは何かを説明できますか? –

+0

私は使用しているアンドロイド用のナビゲーションドロワーです。別のプロジェクトの同様の実装の1つがここにあります:http://pastebin.com/850gaEf4。ペーストビンには、モデル、ローダー、ナビゲーション・ドロワー機能全体の設定が含まれています。 –

関連する問題