Android 中应用程序特定属性的属性
我想将应用程序标题/标签放在 Android 应用程序的中心,但我找不到很多有关如何设置该属性的文档。我发现有几篇文章说我可以创建自定义标题栏并更改清单中的主题,但我忍不住想有一种更简单的方法可以将标题居中。
I want to center the application title/label in my Android app but I can't find a lot of documentation on how to set that property. I have found a couple of posts saying that I can create a custom title bar and change the theme in my manifest but I just can't help thinking there is a simpler way to just center the title.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据我的经验,这方面的文档并不是很好,但我弄清楚了并且我会分享。其实很简单。
Activity 上的自定义居中标题栏:
在
onCreate()
开头向 Activity 添加两行,使其看起来像这样:现在将 mytitle.xml 放入布局目录中。该 xml 文件应如下所示,以将标题文本居中:
就是这样。
In my experience documentation on this isn't great but I figured it out and I'll share. It's actually pretty simple.
Custom centered title bar on your activity:
Add two lines to your activity at the beginning of
onCreate()
so it looks like this:Now put mytitle.xml in your layout directory. This xml file should look something like this to center your title text:
That's it.
您可以使用清单中的
android:label="@string/app_name"
更改任何活动的标签。您也可以用代码来完成。我不确定你还想要什么You can change the label of any of your activities with the
android:label="@string/app_name"
in your manifest. You can do it in code too. I'm not sure what else you want