Niestandardowe atrybuty XML bez niestandardowego widoku w fragmencie

Próbuję dodać niestandardowe atrybuty XML w istniejącym widoku

Dodanie ich do niestandardowego widoku nie jest wielką sprawą, ale nie wiem, jak uzyskać dostęp do tych atrybutów w „podstawowym” widoku (np. TextView, LinearLayout, ImageView ...)

A to jest trudniejsze, gdy zaangażowany jest projekt Fragment i / lub Biblioteka

Do tej pory jest mój kod

Definicje atrybutów celnych i XML (attrs.xml i układ):

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="StarWars">
    <attr name="jedi" format="string" />
    <attr name="rank" format="string" />
</declare-styleable>

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:sw="http://schemas.android.com/apk/res-auto"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

<TextView
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="28dp"
    android:gravity="center_horizontal"
    sw:jedi="Obiwan" />

<TextView
    android:id="@+id/rank"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="28dp"
    android:gravity="center_horizontal"
    sw:rank="Master" />

Ponieważ nadmuchuję ten fragment na Fragment (więc nie ma onCreate z atrybutami arg!), Jedynym sposobem, aby uzyskać atrybuty niestandardowe 2 sw, jest:

Ustaw niestandardowy LayoutInflater.Factory na Fragment LayoutInflater w onCreateView

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  super.onCreateView(inflater, container, savedInstanceState);

  LayoutInflater layoutInflater = inflater.cloneInContext(inflater.getContext());
  layoutInflater.setFactory(new StarWarsLayoutFactory());

  View fragmentView = layoutInflater.inflate(R.layout.jedi, container, false);
  ((TextView) fragmentView.findViewById(android.R.id.jedi)).setText("Yep");

  return fragmentView;
}

Próbuję uzyskać niestandardowe atrybuty w niestandardowym LayoutInflater.Factory:

public class StarWarsLayoutFactory implements Factory {
  @Override
  public View onCreateView(String name, Context context, AttributeSet attrs) {
              *** What to do here ? ***

      return null;
  }
}

Czy ktoś miał takie pytanie?

Czego tu brakuje?

Thx z góry!

questionAnswers(2)

yourAnswerToTheQuestion