Often use the Actionbar text to center the problem, here write a code as follows:
Center the text caption of the Actionbar public static void Centeractionbartitle (activity activity) { int titleid = Activity.getresources (). Getidentifier ("Action_bar_title", "id", "Android"); if (titleid<=0) return; TextView Titletextview = (TextView) Activity.findviewbyid (TitleID); Displaymetrics metrics = activity.getresources (). Getdisplaymetrics (); Linearlayout.layoutparams txvpars = (linearlayout.layoutparams) titletextview.getlayoutparams (); txvpars.gravity = gravity.center_horizontal; Txvpars.width = Metrics.widthpixels; Titletextview.setlayoutparams (txvpars); Titletextview.setgravity (Gravity.center);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Actionbar Center in Android