如何以编程方式设置标题

Can*_*ner 16 android

如何设置当前视图标题(按标题我的意思是电池和时间下面显示的文本(在下面的图像中将是"菜单示例")?我发现许多示例使用清单文件但没有来自代码.

Android Set Title以编程方式

MBy*_*ByD 41

Activity.setTitle() -setTitle("My New Awesome Title!");


Ras*_*sel 8

像这样

public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        this.setTitle("This is my Title");


    }
Run Code Online (Sandbox Code Playgroud)


Pra*_*tik 5

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.foo_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar); 
Run Code Online (Sandbox Code Playgroud)

要么

youractivity.setTitle();
Run Code Online (Sandbox Code Playgroud)