2016-08-26 7 views
0

私はツールチップを作成していますが、thisライブラリを使用して作成しています。そのフォントの色を変更するにはattr以下の説明、これはattr.xmlファイル属性ファイルでテキストの色を定義する方法

declare-styleable name="TooltipLayout"> 
    <attr name="ttlm_padding" format="dimension" /> 
    <attr name="ttlm_strokeColor" format="color" /> 
    <attr name="ttlm_backgroundColor" format="color" /> 
    <attr name="ttlm_strokeWeight" format="dimension" /> 
    <attr name="ttlm_cornerRadius" format="dimension" /> 
    <attr name="ttlm_arrowRatio" format="float" /> 
    <attr name="android:textAppearance" /> 
    <attr name="ttlm_overlayStyle" format="reference" /> 
    <attr name="ttlm_elevation" format="dimension" /> 

    <!-- font file path inside your assets folder --> 
    <attr name="ttlm_font" format="string" /> 

    <!-- textview text gravity --> 
    <attr name="android:gravity" /> 
</declare-styleable> 

に追加するコードですこれは非常に簡単かもしれないが、私は色を与えるとattrファイルの値を指定する方法を理解することができません。

私を親切に案内します。

EDIT

コード

Tooltip.make(context, 
              new Tooltip.Builder(101) 
                .anchor(editText, Tooltip.Gravity.BOTTOM) 
                .closePolicy(new Tooltip.ClosePolicy() 
                  .insidePolicy(true, false) 
                  .outsidePolicy(true, false), 3000) 
                .text("AA") 
                .maxWidth(800) 
                .withArrow(true) 
                .withOverlay(true) 
                .floatingAnimation(Tooltip.AnimationBuilder.DEFAULT).fitToScreen(true) 
                .withStyleId(R.attr.ttlm_backgroundColor,R.color.black_54) 
                .withStyleId(R.color.black) 

                .build() 
            ).show(); 
+1

あなたが求めていることを理解しているなら、 'attrs'に色の値を指定しないでください。これは、値を割り当てることができる属性を定義するところです。実際の値は、レイアウトまたはテーマで指定されます。 –

+0

はい、私は何を求めているのですか?私はコードで次のように書く必要がありますか? R.ttlm_padding =何か? – Kirmani88

+0

レイアウトxmlで、TooltipLayoutタイプのビューを定義します。このファイルで定義した属性はこのファイルで利用でき、someColorAttribute = * your color *などの操作を行うことができます。 ttlm_strokeColor = 0xFFFFFFFF白い線の色です。 –

答えて

1

あなたは宣言-スタイル可能使用しています。名前が示すように、whatを定義する場合は、howではなくスタイル指定することができます。

これにより、レイアウトにスタイルを設定することができます。

<com.mypackage.MyCustomView 
android:layout_width=".." 
... 
app:ttlm_cornerRatius="4dp" /> 

カスタムビューでは、スタイル付き属性を取得してビューに適用する必要があります。例えば

public ToolTipLayout(Context context, AttributeSet attrs, int defStyleAttr) { 
    super(context, attrs, defStyleAttr); 
    init(context, attrs); //override the constructors and make an init method that passes the `AttributeSet` 
} 

private void init(Context context, AttributeSet attrs) { 
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable. TooltipLayout); 
    int buttonType = a.getInt(R.styleable.TooltipLayout_ ttlm_cornerRadius, 0); 
    a.recycle(); 
} 

希望はこのことができます:)

PSを。これを私の頭の中に打ち込んだら、いくつかのタイプミスがあるかもしれません。

+0

ありがとう、 'withStyleId'に' attr'を追加する必要があります。ここで 'attr'を追加する方法を教えてください、今私にエラーメッセージを与えます – Kirmani88

+0

私はコードを更新しました – Kirmani88

関連する問題