在Xamarin隐藏Android标题栏有一个延迟

时间:2015-11-24 12:26:46

标签: android xamarin

我正在尝试隐藏Xamarin Android项目中的标题栏,将其作为Activity.OnCreate中的第一行代码:

Window.RequestFeature(WindowFeatures.NoTitle)

然而,标题仍然短暂显示,然后消失。我根本不希望它显示 - 这可能吗?

感谢。

1 个答案:

答案 0 :(得分:4)

在主题中执行此操作,以便在显示之前没有标题创建:

添加主题

'资源/值/ NoTitleTheme.xml'

[Activity(Theme = "@style/Theme.NoTitle", MainLauncher = true, NoHistory = true)]
public class PlayScriptActivity : Activity

使用主题

package comp4Pack;
import javax.swing.*;
import java.awt.*;

public class Simulation implements Runnable {

    private final int pwidth = 768, pheight = 432;
    private int type;

    private JFrame frame;
    private JPanel panel;

    private boolean running = false;
    private Thread thread;

    /* Type means the following
     * 
     * 0 - Kinematics 
     * 1 - Dynamics (Momentum)
     * 2 - Vectors 
     * 3 - ... 
     * 
     */

    public Simulation(int type){

        this.type = type;

        initSimulation();
        InitSimGraphics i = new InitSimGraphics();
        panel.add(i);

    }

    private void initSimulation(){

        if(type == 0){
            frame = new JFrame("Kinematics Simulation");
        } else if(type == 1){
            frame = new JFrame("Dynamics Simulation");
        } else {
            frame = new JFrame("Vectors Simulation");
        }

        frame.setSize(pwidth, pheight);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);

        panel = new JPanel(new BorderLayout());
        panel.setPreferredSize(new Dimension(pwidth, pheight));
        panel.setMaximumSize(new Dimension(pwidth, pheight));
        panel.setMinimumSize(new Dimension(pwidth, pheight));

        frame.add(panel);
        frame.pack();
        frame.setVisible(true);

    }

    private void initGraphics(){

    }

    public void run() {

        while(running){

            tick();
            render();

        }

        stop();
    }

    private void tick(){

    }

    private void render(){

    }

    public synchronized void start(){
        if(running)
            return;
        running = true;
        thread = new Thread(this);
        thread.start();
    }

    public synchronized void stop(){
        if(!running)
            return;
        running = false;
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}