I have a custom button view.
public class PrayerTimeLabel extends Button { int hours; int minutes; String dayHalf; //am or pm Context parentActivity; PrayerControl parentControl; public PrayerTimeLabel(Context context,PrayerControl parent) { super(context); init(context,parent,0); } public PrayerTimeLabel(Context context, int defStyle, PrayerControl parent) { //super(context, null, R.style.Button_PrayerTimeButton); super(context, null, defStyle); init(context,parent,defStyle); } private void init(final Context context, PrayerControl parent, int defStyle) { parentActivity = context; parentControl = parent; Typeface tf = Typeface.createFromAsset(context.getAssets(),"fonts/digital.ttf"); this.setTypeface(tf); this.setText(false); this.setOnClickListener(new OnClickListener() { public void onClick(View v) { TimeDialog dialogBox = parentControl.getDialogBox(); dialogBox.setTime(hours, minutes, dayHalf); dialogBox.show(); } }); } public void setTime(int hrs, int min, String half,boolean signalParent) { hours = hrs; minutes = min; dayHalf = half; this.setText(signalParent); } public void setText(boolean signalParent) { super.setText(String.format("%02d", hours)+":"+String.format("%02d", minutes)+" "+dayHalf); if(signalParent){ parentControl.setPrayerTime(hours, minutes, dayHalf); } } }
and I have the following style defined in my .xml style
<style name="Button.PrayerTimeButton" parent="@android:style/TextAppearance.Widget.Button"> <item name="android:background">#000</item> <item name="android:textSize">18dp</item> <item name="android:textColor">#FFFF00</item> </style>
The extended button does not receive this style. Can someone point out what I'm doing wrong? I was looking for a solution and found this one . Can anyone suggest something?
Note. I cannot use XML to apply styles. He must be a constructor.
Edit:
The following is the class in which this custom button is created and used. I removed many irrelevant lines of code
public class PrayerControl extends LinearLayout { protected PrayerTimeLabel prayerTimeButton; protected String prayerName; protected static int counter=0; public PrayerControl(Context context) { super(context); init(context); } public PrayerControl(Context context, AttributeSet attrs) { super(context, attrs); getXMLAttributes(context, attrs); init(context); } protected void getXMLAttributes(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.PrayerControl); prayerName = a.getString(R.styleable.PrayerControl_name); dayHalf = a.getString(R.styleable.PrayerControl_dayHalf); hours = a.getInteger(R.styleable.PrayerControl_hours, 4); minutes = a.getInteger(R.styleable.PrayerControl_minutes, 30); ltrProgress = a.getInteger(R.styleable.PrayerControl_postNamazInterval, 0); rtlProgress = a.getInteger(R.styleable.PrayerControl_preNamazInterval, 0); intervalMax = a.getInteger(R.styleable.PrayerControl_intervalMax, 30); a.recycle(); } protected void init(Context context) { counter++; parentActivity = context; this.setOrientation(LinearLayout.HORIZONTAL); this.setId(counter); prayerTimeButtonStyle = R.style.Button_PrayerTimeButton; initializePrayerTimeButton(); } protected void initializePrayerTimeButton() { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, 40); params.gravity = Gravity.CENTER;