android - Toolbar in fragment doesn't display its title -


the style of activity "theme.appcompat.light.noactionbar". there toolbar in fragment, added activity later.

i cannot set title of actionbar. codes below don't work. please me. how set title of toolbar in fragment?

//in fragment     @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.fragment_main2, container, false);         toolbar toolbar = (toolbar) rootview.findviewbyid(r.id.toolbar);         int = getarguments().getint(arg_section_number);         toolbar.settitle("aaa");         ((appcompatactivity) getactivity()).setsupportactionbar(toolbar);          charsequence title = ((appcompatactivity) getactivity()).getsupportactionbar().gettitle();          ((appcompatactivity) getactivity()).getsupportactionbar().setdisplayhomeasupenabled(true); 

try

@override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.fragment_main2, container, false);         toolbar toolbar = (toolbar) rootview.findviewbyid(r.id.toolbar);         int = getarguments().getint(arg_section_number);          ((appcompatactivity) getactivity()).setsupportactionbar(toolbar);            charsequence title = ((appcompatactivity) getactivity()).getsupportactionbar().gettitle();          ((appcompatactivity) getactivity()).getsupportactionbar().setdisplayhomeasupenabled(true); 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -