I have a RecyclerView
, in each item there's a (Share) button that prompts a custom dialog which contains a TextView
and a Button
.
so, I build the custom dialog inside the Adapter
of RecyclerView
, everything is fine except for the button's appearance.
it looks like there's a white overlay on top of it and when I click on it, the overlay slightly disappears.
This is what the Button looks like in xml:
here's my custom dialog layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:theme="@style/AppTheme">
<TextView
android:id="@+id/tv_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:padding="@dimen/fab_margin"
android:textSize="8pt"
/>
<Button
android:id="@+id/btn_copy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/copy_address"
android:theme="@style/button"/>
</LinearLayout>
and this is the java code creating the dialog:
AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
builder.setView(inflater.inflate(R.layout.share_dialog, null));
builder.setTitle(view.getContext().getResources().getString(R.string.share));
share = builder.create();
share.show();
Note: I think the problem is related to the Inflater, particularly this line:
LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
because in MainActivity it works fine when I replace it by this:
LayoutInflater inflater = MainActivity.this.getLayoutInflater();
but I can't use it since I can't get Activity from inside the adapter.
I hope my question is clear, I'd appreciate your help.
Edit: code of @style/button
<style name="button" parent="ThemeOverlay.AppCompat.Light">
<item name="colorControlHighlight">@color/colorPrimaryDark</item>
<item name="colorButtonNormal">@color/colorGray</item>
<item name="android:textColor">@color/colorWhite</item>
<item name="android:colorAccent">@color/colorPrimary</item>
</style>