how to set custom title bar TextView Value dynamically in android?

前端 未结 5 2008
离开以前
离开以前 2020-12-05 03:20

friends,

i have created custom title bar using following titlebar.xml file with code

 


        
5条回答
  •  遥遥无期
    2020-12-05 03:55

    This is the way to set the custom title:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    
        setContentView(R.layout.main);
    
        if ( customTitleSupported ) {
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitle);
        }
    
        final TextView myTitleText = (TextView) findViewById(R.id.myTitle);
        if ( myTitleText != null ) {
            myTitleText.setText("========= NEW TITLE ==========");
            myTitleText.setBackgroundColor(Color.GREEN);
        }
    
    
    }
    

提交回复
热议问题