I've run into serious problem with theme after updating to appcompat-v7:22. Issue described below does not occur with appcompat-v7:21
I have activity with one statically added fragment. Fragment view is created programmatically only (no layout is inflated). Final activity view contains 2 buttons: one created directly in Activity layout, second added programmatically via Fragment. Second button should look similar to the first one as no custom styles or attribute values are assigned:
App theme extends Theme.AppCompat.NoActionBar
Activity layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:text="Super Button"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<fragment
android:id="@+id/myfragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.jskierbi.appcompat22test.MainFragment" />
</LinearLayout>
Fragment class:
public class MainFragment extends Fragment {
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
LinearLayout layout = new LinearLayout(getActivity());
layout.setOrientation(LinearLayout.VERTICAL);
Button btn = new Button(getActivity());
btn.setText("Click me!");
layout.addView(btn);
return layout;
}
}
I've separated this issue to new project here: https://github.com/jskierbi/appcompat-v7-22-bug
Is this a bug or am I missing something? Is it possible to make a workaround for this?
Edit
This is not a bug. <Button>
widget defined in layout inflates to TintButton object in view hierarchy. Possible fix is to create TintButton instead of Button in code. Warning TintButton is inside internal package so it is not supposed to be used in production code.