1. 给支付回调的界面 配置一个theme
<!--微信支付 -->
在styles内设置一个样式
<style name="wx_theme" parent="AppTheme">
<!--<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">-->
<!-- Customize your theme here. -->
<item name="android:windowBackground">@color/transparence</item>
<item name="android:windowIsTranslucent">true</item>
</style>
在manifest中使用这个样式
<activity
android:name=".wxapi.WXPayEntryActivity"
android:exported="true"
android:theme="@style/wx_theme"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="你的码" />
</intent-filter>
</activity>
色值
<color name="transparence">#00000000</color>//透明
2.在WXPayEntryActivity 界面的回调界面内 的取消回调内,隐藏所有布局,关闭界面
@Override
public void onResp(BaseResp baseResp) {
if (baseResp.errCode == 0) {
if (BaseApplication.chongzhi.equals("1")) {
Toast.makeText(this, "购买成功", Toast.LENGTH_SHORT).show();
ly_chenggong.setVisibility(View.GONE);
ly_quxiao.setVisibility(View.GONE);
ly.setBackgroundColor(getResources().getColor(R.color.transparence));
finish();
} else {
ly_chenggong.setVisibility(View.VISIBLE);
ly_quxiao.setVisibility(View.GONE);
//支付成功 由于 刷新 我的购买记录 未购买列表
Intent intent = new Intent();
intent.setAction(action);
sendBroadcast(intent);
//生成 订单就 刷新 我的页面 使其显示是否 有订单
Intent intent2 = new Intent();
intent2.setAction(BaseApplication.update);
sendBroadcast(intent2);
}
}
if (baseResp.errCode == -2) {
//就是在这里取消支付,隐藏布局,关闭界面
ly_chenggong.setVisibility(View.GONE);
ly_quxiao.setVisibility(View.GONE);
ly.setBackgroundColor(getResources().getColor(R.color.white));
finish();
}
}
4.//取消支付我們是隐藏布局,使界面透明 来跳过取消支付的回调,但是我们支付成功还是要显示界面的, 不能让支付成功界面出现透明,所以要在界面布局的最外层设置白色的背景色