如何使android动作栏标题中心对齐?

如何使android动作栏标题中心对齐?,第1张

概述我尝试了自己的“自定义 *** 作”栏,以获取中间的动作标题.有效.但是,在“ *** 作”栏中添加选项菜单后,标题再次向左移动.为了让标题以动作栏的中间为中心,该怎么办? 我的代码是: ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplaySho 我尝试了自己的“自定义 *** 作”栏,以获取中间的动作栏标题.有效.但是,在“ *** 作”栏中添加选项菜单后,标题再次向左移动.为了让标题以动作栏的中间为中心,该怎么办?
我的代码是:
Actionbar actionbar = getActionbar();    actionbar.setdisplayHomeAsUpEnabled(false);    actionbar.setdisplayShowCustomEnabled(true);    actionbar.setdisplayShowTitleEnabled(false);        actionbar.setdisplayUselogoEnabled(false);    actionbar.setdisplayShowHomeEnabled(false);    actionbar.setdisplayOptions(Actionbar.disPLAY_SHOW_CUSTOM);     VIEw cVIEw = getLayoutInflater().inflate(R.layout.custom_actionbar,null);    actionbar.setCustomVIEw(cVIEw);

我的布局是

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="wrap_content"androID:layout_height="wrap_content"androID:layout_gravity="center"androID:background="@androID:color/holo_blue_light"androID:orIEntation="vertical" ><TextVIEw    androID:ID="@+ID/appTitle"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_centerInParent="true"    androID:layout_gravity="center_horizontal|center_vertical"    androID:gravity="center_horizontal|center_vertical"    androID:text="@string/app_name" />
解决方法 我相信,您正在使用以下设置您的自定义主题.
getSupportActionbar().setdisplayOptions(Actionbar.disPLAY_SHOW_CUSTOM); getSupportActionbar().setCustomVIEw(R.layout.abs_layout);

如果没有,请添加第一行.并且您的自定义布局中的文本居中. (重力=中心)

另外我发现一个类似的链接here和here.希望这有帮助.

也试试这个.

我能够通过不显示标题来完成我想要的
该活动,而是使用您建议的customVIEw.钥匙
我错过了一段时间,你必须使用setCustomVIEw(VIEw,
ActionVar.LayoutParams)方法,以获取自定义视图
居中,只需在自定义视图中设置一个layout_gravity =“center”即可
布局文件不起作用这是一个简短的代码段,显示了我如何
让它工作:

TextVIEw customVIEw = (TextVIEw)LayoutInflater.from(this).inflate(R.layout.actionbar_custom_Title_vIEw_centered,null);            Actionbar.LayoutParams params = newActionbar.LayoutParams(Actionbar.LayoutParams.MATCH_PARENT,Actionbar.LayoutParams.MATCH_PARENT,Gravity.CENTER);            customVIEw.setText("Some centered text");            getSupportActionbar().setCustomVIEw(customVIEw,params);

这种方法在我至少在3.2,2.3和2.2设备上工作.

来源https://groups.google.com/forum/#!msg/actionbarsherlock/A9Ponma6KKI/Llsp41jWLEgJ

总结

以上是内存溢出为你收集整理的如何使android动作栏标题中心对齐?全部内容,希望文章能够帮你解决如何使android动作栏标题中心对齐?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1130803.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存