设置Activity背景完全透明
设置样式Theme.Translucent,可用的样式有:
@android:style/Theme.Translucent
@android:style/Theme.Translucent.NoTitleBar
@android:style/Theme.Translucent.NoTitleBar.Fullscreen
Manifest.xml
<activity
android:name=".SelectVideosActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:screenOrientation="portrait" />
注意:如果直接使用了,你的程序也许会直接崩溃!原因可能是你的Activity继承的是V7包的AppCompatActivity,这时你所使用的主题要与Theme.AppCompat兼容,否则程序就会崩溃了。
解决方案1:
使你的Activity继承android.app包的Activity。
解决方案2:
重新写一个主题,继承自Theme.AppCompat的主题
<style name="MyTranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
</style>
Manifest.xml
<activity
android:name=".activity.edit.SelectVideosActivity"
android:theme="@style/MyTranslucentTheme"
android:screenOrientation="portrait" />