Android知识笔记:Android 仿iOS 侧滑关闭Activity框架透底问题(2)

本文探讨了在Android中如何在运行时修改Activity的主题,特别是如何通过`convertToTranslucent`和`convertFromTranslucent`系统API实现窗口透明度的改变,以及使用反射进行操作的可能。文章还涉及了性能影响和优化策略,如仅在特定用户交互时进行透明度调整。
摘要由CSDN通过智能技术生成

default:

break;

}

}

protected void reload() {

Intent intent = getIntent();

overridePendingTransition(0, 0);

intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

finish();

overridePendingTransition(0, 0);

startActivity(intent);

}

其实设置主题必须在任何view创建之前,所以我们不可能在activity的onCreate之后来更改主题,如果一定要做,就只能调用setTheme(),然后调用recreate(),重新创建一个activity,并且销毁上一个activity; 所以这个方案并不可行,整个界面必须销毁重建。 已知的Android theme修改方式

  • AndroidManifest 设置Activity Theme

  • 在Activity setContentView执行前 调用setTheme

可以通过其他方式修改Activity windowIsTranslucent 属性吗?

方案B+:反射动态设置Activity windowIsTranslucent

查阅Activity源码,看一下他是如何变成透明的

/**

  • Convert a translucent themed Activity {@link android.R.attr#windowIsTranslucent} back from

  • opaque to translucent following a call to {@link #convertFromTranslucent()}.

  • Calling this allows the Activity behind this one to be seen again. Once all such Activities

  • have been redrawn {@link TranslucentConversionListener#onTranslucentConversionComplete} will

  • be called indicating that it is safe to make this activity translucent again. Until

  • {@link TranslucentConversionListener#onTranslucentConversionComplete} is called the image

  • behind the frontmost Activity will be indeterminate.

  • This call has no effect on non-translucent activities or on activities with the

  • {@link android.R.attr#windowIsFloating} attribute.

  • @param callback the method to call when all visible Activities behind this one have been

  • drawn and it is safe to make this Activity translucent again.

  • @param options activity options delivered to the activity below this one. The options

  • are retrieved using {@link #getActivityOptions}.

  • @return tr

  • 22
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值