styles.xml
とstyles.xml(v21)
の2つのスタイルが定義されています。どちらも、特定のデフォルトアンドロイドテキストスタイルにリンクするtextAppearance
属性を含んでいます。Android:styles.xmlで定義された特定のスタイルからtextColor属性を取得
のstyles.xml
<style name="NotificationTitle">
<item name="android:textAppearance">
@android:style/TextAppearance.StatusBar.EventContent.Title
</item>
</style>
のstyles.xml(V21)
<style name="NotificationTitle">
<item name="android:textAppearance">
@android:style/TextAppearance.Material.Notification.Title
</item>
</style>
これらのデフォルトのスタイルが含まれているいくつかのテキスト属性:textColor
、textSize
、など:
...
<style name="TextAppearance.Material.Notification.Title">
<item name="textColor">@color/primary_text_default_material_light</item>
<item name="textSize">@dimen/notification_title_text_size</item>
</style>
...
私はこれをtextColor
私のカスタムスタイルの名前(この例ではNotificationTitle)の名前でプログラムで取得する必要があります。 obtainStyledAttributes
を使用して取得しようとしましたが、返されません。私は何をすべきか?
<style name="NotificationTitle" parent="TextAppearance.AppCompat.Notification.Title"/>
<style name="NotificationText" parent="TextAppearance.AppCompat.Notification.Line2"/>
、すべてが他の部分とうまく:私は少し遅れて答えを持つが、私は変更のビットでコードをしようとした場合
int resultColor;
int[] attrs = {android.R.attr.textColor};
TypedArray ta = context.obtainStyledAttributes(R.style.NotificationText, attrs);
if (ta != null) {
resultColor = ta.getColor(0, Color.TRANSPARENT);
ta.recycle();
}
正しいコンテキストを渡していることを確認してください。 –
文脈が適切である、私はちょうど - 私が直接渡す場合チェックした。 'android.R.style.TextAppearance_Material_Notification_Title'を 'obtainStyledAttributes'に設定すると、正しい色が返されます。しかし、私がカスタムスタイル 'R.style.NotificationText'を渡すと、何も返されません。 –