2012-04-16 14 views
11

मैं अभी एक कस्टम वरीयता के साथ टंकण कर रहा हूं, और मैं इसे टेक्स्ट व्यू का उपयोग करके एक लेबल देना चाहता हूं। हालांकि मुझे setTextView()प्रोग्रामेटिक रूप से setTextSize का उपयोग करें? Attr/textAppearanceLarge

का उपयोग करके टेक्स्ट आकार को "बड़े" में निर्दिष्ट करने का कोई तरीका नहीं दिख रहा है, मुझे यहां क्या याद आ रही है?

उत्तर

38
TextView title = new TextView(context); 
title.setTextAppearance(context, android.R.attr.textAppearanceLarge); 

या इसके बाद के कोड की कोशिश

setTextAppearance(context, android.R.style.TextAppearance_Large); 

का उपयोग करें और

+12

यह काम नहीं कर रहा है, सही जवाब 'है setTextAppearance (संदर्भ, android.R.style.TextAppearance_Large);' – tbruyelle

+0

यह ऊपर टिप्पणी काम करता है, इस सवाल का जवाब जेबी पर नहीं है । – secureboot

+0

इसके साथ समस्या यह है कि आप इस तथ्य के बारे में नहीं जानते कि android.R.attr.textAppearanceLroid बिंदु Android.R.style.TextAppearance_Large – njzk2

0

कोशिश वाक्य रचना शुरू कर एपीआई स्तर 23 (Marshmallow) के बाद से बदल गया है के रूप में भी कुछ उपयोगकर्ताओं को उल्लेख किया है कि android.R.attr.textAppearanceLarge के लिए काम नहीं किया क्योंकि यह मेरे लिए काम नहीं करता था। यहाँ अद्यतन संस्करण ...

Button b = new Button(getContext()); 

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) 
    b.setTextAppearance(android.R.style.TextAppearance_Medium); 
else 
    b.setTextAppearance(getContext(), android.R.style.TextAppearance_Medium); 
संबंधित मुद्दे