Android 透明应用
来源:互联网 发布:国外域名注册商有那些 编辑:程序博客网 时间:2024/06/14 08:25
想要在应用中搞一个透明主题,可以在Manifest中更改android:theme
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"><!-- 改这里 --> <activity android:name=".MainActivity">并让MainActivity继承Activity而不是AppCompatActivity
public class MainActivity extends Activity { //继承Activity @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }}
这样开启的应用就变成透明主题的了,注意屏幕中间的HelloWorld,字还在表示应用已开启。
如果不用Activity,会报异常 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
------------------------------------------------------------------------------------------------------------------------------
但是为什么要继承Activity而不是AppCompatActivity呢?
Activity is the baseline. Every activity inherits from Activity, directly or indirectly.
FragmentActivity is for use with the backport of fragments found in the support-v4 and support-v13 libraries. The native implementation of fragments was added in API Level 11, which is higher than your proposed minSdkVersion values. The only reason why you would need to consider FragmentActivity specifically is if you want to use nested fragments (a fragment holding another fragment), as that was not supported in native fragments until API Level 17.
AppCompatActivity is from the appcompat-v7 library. Principally, this offers a backport of the action bar. Since the native action bar was added in API Level 11, you do not need AppCompatActivity for that. However, current versions of appcompat-v7 also add a limited backport of the Material Design aesthetic, in terms of the action bar and various widgets. There are pros and cons of using appcompat-v7, well beyond the scope of this specific Stack Overflow answer.
ActionBarActivity is the old name of the base activity from appcompat-v7. For various reasons, they wanted to change the name. Unless some third-party library you are using insists upon an ActionBarActivity, you should prefer AppCompatActivity over ActionBarActivity.
So, given your minSdkVersion in the 15-16 range:
If you want the backported Material Design look, use AppCompatActivity
If not, but you want nested fragments, use FragmentActivity
If not, use Activity
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
有关AppCompatActivity透明化处理的失败探索历程
http://blog.csdn.NET/lq2007lq/article/details/52606797
当Activity继承于AppCompatActivity时,只能使用Theme.AppCompat下的主题。而这些主题并没有Translucent.提示错误:
Java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
可以采用自定义主题来弥补AppCompat中无透明主题,方式如下:
- Android 透明应用
- Android launcher2 应用列表背景透明/透明壁纸
- [学习记录]android 透明色应用
- android Launcher3应用列表修改透明背景
- Android应用的全透明效果--Activity及Dialog的全透明
- android 4.1.2 launcher2实现应用列表背景透明
- android 4.1.2 launcher2实现应用列表背景透明
- android 沉浸式 状态栏透明 与应用头部背景一样
- android 透明
- 嵌入式透明传输应用
- 应用全屏状态栏透明
- android Acitivity启动时全透明设置 一个应用调用另一个应用中的某些功能
- QT应用之透明背景
- android 实现应用起动界面上有一层透明的功能指导界面
- android 实现应用起动界面上有一层透明的功能指导界面
- android 实现应用起动界面上有一层透明的功能指导界面
- 转niutao:android 4.1.2 launcher2实现应用列表背景透明
- android 4.1.2 launcher2实现像4.4launcher3应用列表背景透明的效果
- Android 多媒体之MediaStore
- 《你不知道的JavaScript》读书笔记(一):变量的声明和变量提升
- [BZOJ1046][HAOI2007]上升序列(dp+贪心)
- TCP/IP
- CSS实现居中
- Android 透明应用
- 【IOI2001】Mobile phones(二维树状数组)
- centos-7 部署hadoop2.5.1 >>>> 分布式 HDFS(三)
- 机器学习实战第四章朴素贝叶斯算法照葫芦画瓢算法实践
- 回归模型拟合效果的判断(一)
- mybatis概念和基本原理
- MyBatis高级查询之resultMap的应用
- .javascript如何使用继承
- hmm------java代码实现的viterbi算法