gpt4 book ai didi

android - 具有透明背景的 Activity

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:24:37 62 4
gpt4 key购买 nike

我正在创建一个可重复使用的加载屏幕以在 Activity 之间使用,在 LoadingActivity 上我添加了一个半透明的背景资源,但我看不到旧的 Activity。

public class LoadingActivity extends Activity {
public static int REQUEST_LOADING_SCREEN = 40;

@Override
protected void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);

FrameLayout mainLayout = new FrameLayout(this);

mainLayout.setBackgroundResource(R.drawable.background_translucent);

LinearLayout layout = new LinearLayout(this);
layout.setGravity(Gravity.CENTER);

LayoutParams params = LayoutParamsFactory.newMatchFrameLP();
params.gravity = Gravity.CENTER;
mainLayout.addView(layout, params);

ProgressBar bar = new ProgressBar(this);
bar.setIndeterminate(true);
layout.addView(bar, LayoutParamsFactory.newWrapLinearLP());

TextView text = new TextView(this);
text.setText("Loading...");
layout.addView(text, LayoutParamsFactory.newWrapLinearLP());

setContentView(mainLayout);
}

public static void openFor(Activity activity) {
Intent intent = new Intent(activity, LoadingActivity.class);
activity.startActivityForResult(intent, REQUEST_LOADING_SCREEN);
}

public static void closeFrom(Activity activity) {
activity.finishActivity(REQUEST_LOADING_SCREEN);
}
}

编辑:

即使有:

mainLayout.setBackgroundColor(Color.TRANSPARENT);
layout.setBackgroundColor(Color.TRANSPARENT);

背景还是黑色

最佳答案

您是否尝试过通过 list 文件为 Activity 设置主题?

<activity android:name=".LoadingActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />

关于android - 具有透明背景的 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7880155/

62 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com