相关疑难解决方法(0)

必须在添加内容之前调用requestFeature()

我正在尝试实现自定义标题栏:

这是我的助手课程:

import android.app.Activity;
import android.view.Window;

public class UIHelper {
    public static void setupTitleBar(Activity c) {
        final boolean customTitleSupported = c.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

        c.setContentView(R.layout.main);

        if (customTitleSupported) {
            c.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我在onCreate()中调用它的地方:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setupUI();
}

private void setupUI(){
     setContentView(R.layout.main);
     UIHelper.setupTitleBar(this);
}
Run Code Online (Sandbox Code Playgroud)

但我得到错误:

requestFeature() must be called before adding content
Run Code Online (Sandbox Code Playgroud)

android android-layout android-activity

134
推荐指数
4
解决办法
11万
查看次数

标签 统计

android ×1

android-activity ×1

android-layout ×1