I have theme that specifies textColor for TextView as red.
I am using LayoutInflater to instantiate TextView. The problem is that styles are not applied to TextView
I usually come across this issue on inflating a custom view. Here is what I personally do to keep the same theme of the activity in the CustomView
public class CustomView extends ViewGroup{
public CustomView (Context context) {
super(context);
init(context);
}
public CustomView (Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public CustomView (Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
@TargetApi(21)
public CustomView (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
private void init(Context context) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = mInflater.inflate(R.layout.review_list_item, this, true);
//rest of view initialization
}
}