2013-03-01 13 views
5

私は自分のプロジェクトで使用するJARとしてFacebook Android SDKをエクスポートしようとしています。R.styleableリソースを動的にロードする方法は?

これは、すべてのリソースを動的にロードする必要があります。

例えば、私はこれと同様の変更を加える必要があります:

//findViewById(R.id.com_facebook_login_activity_progress_bar).setVisibility(View.VISIBLE); 
int viewID = getResources().getIdentifier("com_facebook_login_activity_progress_bar", "id", getPackageName()); 
findViewById(viewID).setVisibility(View.VISIBLE); 

コメント行は、オリジナルを示しており、以下の2行は、私は動的に同じリソースをロードするために作られた変化を示します。

Facebook SDKはR.styleableリソースを宣言しており、動的にロードする方法を理解できません。ここでは、元のコードは次のとおりです。

private void parseAttributes(AttributeSet attrs) { 
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.com_facebook_profile_picture_view); 
    setPresetSize(a.getInt(R.styleable.com_facebook_profile_picture_view_preset_size, CUSTOM)); 
    isCropped = a.getBoolean(R.styleable.com_facebook_profile_picture_view_is_cropped, IS_CROPPED_DEFAULT_VALUE); 
    a.recycle(); 
} 

はその後attrs.xmlで、次のように宣言されています:

<declare-styleable name="com_facebook_profile_picture_view"> 
     <attr name="preset_size"> 
      <!-- Keep in sync with constants in ProfilePictureView --> 
      <enum name="small" value="-2" /> 
      <enum name="normal" value="-3" /> 
      <enum name="large" value="-4" /> 
     </attr> 
     <attr name="is_cropped" format="boolean" /> 
    </declare-styleable> 

どのように私は(例えばR.styleable参照を置き換える)、動的にこのリソースをロードすることができますか?

+1

は、[プログラム的に<宣言-styleable>リソースへのアクセス]を参照してください(http://stackoverflow.com/questions/13816596/accessing-宣言スタイル可能なリソースプログラム的に)現在の問題を解決するのに役立つかもしれない –

+0

素晴らしい、すばやい応答をありがとう。それは私が必要としたものだった。あなたが答えとして投稿するなら、私はそれをチェックするでしょう! – ch3rryc0ke

答えて

3

誰かが特にFacebook SDKをjarファイルとしてエクスポートしようとしている場合は、ここで質問に答えています。

私はこの質問への答えで説明した機能を使用: Accessing <declare-styleable> resources programatically

private void parseAttributes(AttributeSet attrs) { 
    int attrArray[] = StyleableHelper.getResourceDeclareStyleableIntArray(getContext(), "com_facebook_profile_picture_view"); 
    //TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.com_facebook_profile_picture_view); 
    TypedArray a = getContext().obtainStyledAttributes(attrs, attrArray); 

    setPresetSize(a.getInt(0, CUSTOM)); 
    isCropped = a.getBoolean(1, IS_CROPPED_DEFAULT_VALUE); 
    //setPresetSize(a.getInt(R.styleable.com_facebook_profile_picture_view_preset_size, CUSTOM)); 
    //isCropped = a.getBoolean(R.styleable.com_facebook_profile_picture_view_is_cropped, IS_CROPPED_DEFAULT_VALUE); 
    a.recycle(); 
} 
関連する問題