私は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"></string>
<string name="pinterest_square"></string>
<string name="google_plus_square"></string>
<string name="google_plus"></string>
<string name="money"></string>
<string name="caret_down"></string>
<string name="caret_up"></string>
<string name="caret_left"></string>
<string name="caret_right"></string>
<string name="columns"></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()));
}
}
は、なぜあなたはちょうどここに同等のフォント素晴らしいPNGアイコンをダウンロードすることができません:http://www.flaticon.com/packs/font-awesome –