Activity的透明背景度的设置

时间:2021-04-13 03:53:16
<style name="custom" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item><!-- 边框 -->
<item name="android:windowIsFloating">true</item><!-- 是否悬浮在activity上 -->
<item name="android:windowIsTranslucent">true</item><!-- 半透明 -->
<item name="android:windowNoTitle">true</item><!-- 无标题 -->
<item name="android:windowBackground">@android:color/transparent</item><!-- 背景透明 -->
<item name="android:backgroundDimEnabled">false</item><!-- 模糊 -->
<item name="android:backgroundDimAmount">0.6</item><!-- 灰度 -->
<item name="android:windowContentOverlay">@null</item><!-- 窗口是否有遮盖 -->
<item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item><!-- Activity切换动画效果,也可以自定义 -->
<item name="android:colorBackgroundCacheHint">@null</item><!-- 背景缓存颜色 -->
</style>
<activity android:name=".activity.ShareActivity"
android:theme="@style/custom">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
public class ShareActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//无title
requestWindowFeature(Window.FEATURE_NO_TITLE);
//全屏
// getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN , WindowManager.LayoutParams. FLAG_FULLSCREEN);
setContentView(R.layout.activity_share);


WindowManager.LayoutParams windowLP1 = getWindow().getAttributes();
windowLP1.dimAmount = 0.5f;
getWindow().setAttributes(windowLP1);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
}
}

搞定。
参考http://www.cnblogs.com/a284628487/p/3175886.html