2011-07-04 9 views
3

私のカスタムでカスタム文字列属性を追加し、私はこのように、Stringプロパティのタイトルを宣言する必要があります。 私は値/ attrs.xmlでこのプロパティを指定した:私のコードで私はTableLayout由来cusomビューを持っているアンドロイドビュー

<declare-styleable name="NavigationControllerView"> 
    <attr name="title" format="string"/> 
    ... 
</declare-styleable> 

は私がしようとしている:

public class NavigationControllerView extends TableLayout { 
public NavigationControllerView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    View.inflate(getContext(), R.layout.inc_header, this); 
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NavigationControllerView); 
    CharSequence title = a.getString(R.styleable.NavigationControllerView_title); 
    if (title != null) 
     setTitle(title.toString()); 
} 
... 

が、運が、タイトルは常にnullです。私はどこが間違っているのか分かりますか?接頭辞:

答えて

1

あなたは

<com.mycompany.controls.NavigationControllerView 
    xmlns:app="http://schemas.android.com/apk/res/onroad" 
    app:title="@string/nav_title" 
... /> 

アプリをお見逃しなく使用する必要があります。 正しい名前空間uriも使用する必要があります。

+0

アップですが、アプリケーション接頭辞Titleを使用しても、リソース参照を指定することも、直接文字列値 – ZlobnyiSerg

+0

を指定することもできません。カスタムネームスペースを使用していますか?私はxmlnsを使用します:app = "http://schemas.android.com/apk/res/'packagepath" "ここで 'packagepath' - ルートパッケージパス – woodshy

+0

右!ありがとう、スキーマは本当に形式でなければなりません:http://schemas.android.com/apk/res/com.mycompany.myapp 答えにxmlns:appを修正してください。正しいとマークします – ZlobnyiSerg