简体   繁体   English

如何在 android 3.0 的标题栏中添加图像?

[英]How can I add an image to the title bar in android 3.0?

I am learning android 3.0.我正在学习 android 3.0。 Can any one tell How can add Image in Title bar in android 3.0?谁能告诉如何在 android 3.0 的标题栏中添加图像? In developer site they are telling by default it will come.but for me it is not coming.在开发人员网站中,他们默认会告诉它会来。但对我来说它不会来。 Thanks in advance.提前致谢。

You will have to create Custom Title Bar Layout to add your own image in titlebar.And then you can use following code to assign the titlebar to your view您必须创建自定义标题栏布局才能在标题栏中添加您自己的图像。然后您可以使用以下代码将标题栏分配给您的视图

    boolean customTitleSupported;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    if (customTitleSupported) {
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_tittlebar_layout);         

        }
        setContentView(R.layout.main);
   }  

here custom_tittlebar_layout refers to your custom titlebar layout with image.这里 custom_titlebar_layout 是指您自定义的带有图像的标题栏布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM