Ich arbeite an einem Android-Projekt, in dem ich eine Navigationsleiste, die eine Liste von GroupSection
Objekte zeigt. Alle GroupSection-Objekte enthalten ein Abschnittssymbol. Die Schubladensymbole werden durch eine TypedArray- und einige Android-spezifische Syntax bestimmt, um die Ressource zu erhalten. Ich möchte das durch ein font-awesome Icon ersetzen. Jedes groupSection-Objekt hat einen Getter groupSection.getSectionIcon();
, der mir die Zeichenfolge des Symbols zurückgibt. Ich habe die Symbole in String.xml hinzugefügt und die fontawesome-webfont.ttf
im Verzeichnis Assets.Android: Wie Navigation Navigationsschublade Symbole mit font-awesome Symbole ersetzen (Symbole verfügbar)
Ich kann einfach nicht herausfinden, wie das typisierte Array mit font-awesome-Symbol zu ersetzen. Ich habe versucht, findViewByID(R.id.awesome_icon).getId()
, und einige andere Möglichkeiten. Vielen Dank.
Code:
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()));
}
Probe von string.xml:
<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>
Wie in der for-Schleife kann ich direkt auf das Symbol String mit Getter, aber Einstellung ist es, wo die Ausgabe liegt . Jede Hilfe wäre nett. Vielen Dank. :-)
aktualisieren
habe ich versucht, den Code unten, wo ich manuell einstellen würde, aber ich bekomme Fehler für das auch:
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)
Code:
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()));
}
}
Warum kann man nur hier gleichwertig Font ehrfürchtige PNG-Icons herunterladen: http://www.flaticon.com/packs/font-awesome –