Your class might needs to extend View not the TextView, that helps. Warm Regards, *Mukesh Kumar*, Android Consultant/Freelancer, India,Hyderabad.
On Wed, Nov 30, 2011 at 4:56 PM, Danny S. <[email protected]>wrote: > Hi, > > I want to create a custom TextView that uses custom Typeface. I do > this, cause I won't set Typeface for each TextView within the code. I > created a class: > > public class MyTextView extends TextView { > public MemoryTextView(Context context, AttributeSet attrs) { > super(context, attrs); > > // retrieve attributes > TypedArray array = mContext.obtainStyledAttributes(attrs, > R.styleable.MemoryTextView); > > String font = > array.getString(R.styleable.MemoryTextView_ttfName); > // set font if defined, otherwise use standard font > if (font != null) > setFont(font); > > // free up memory > array.recycle(); > } > } > > I created the attributes for my view within the attrs.xml. And I can > use the view and see my custom font. > > In Layout I use my view this way: > <my.package.structure.views.MyTextView > android:layout_width="wrap_content" > android:layout_height="fill_parent" > myTextView:ttfName="AldrichRegular" > myTextView:text="@string/app_name" > android:textColor="@color/white" > android:textStyle="bold" > android:textSize="18sp" > android:gravity="center" /> > > Now the Problem: android based attributes I set does not work. My text > is not bold, is not sized 18sp and gravity is not set like I would. If > I add the android attribute to my "declare-styleable" it is used (e.g. > the gravity). > > <declare-styleable name="MemoryTextView"> > <attr name="android:gravity" /> > ... other custom attributes > </declare-styleable> > > But I can not list all the possible TextView styles to this list. It > seems not to be the clear way. Where is my mistake? I only want a > TextView with all of it's behavior and additional functionality... > > Thanks a lot, > -Danny > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- Warm Regards, *Mukesh Kumar*, Android Consultant/Freelancer, India,Hyderabad. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

