使用活动在Android中居中标题栏
因此,我尝试使用第一个activity.java类来集中我的应用程序标题 这是我的密码使用活动在Android中居中标题栏,android,class,android-activity,centering,titlebar,Android,Class,Android Activity,Centering,Titlebar,因此,我尝试使用第一个activity.java类来集中我的应用程序标题 这是我的密码 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); -----setTitle(R.string.app_name1); //Sets the title for this activity using the app_name1 string
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-----setTitle(R.string.app_name1); //Sets the title for this activity using the app_name1 string
setContentView(R.layout.main);
所以带-,的那一行是我标题的代码,当然,在我真正的代码中并没有,只是在这个问题上。我使用字符串app_名称从中提取标题,那么我如何准确地将其居中?谢谢大家! 对于居中标题栏,您可以创建自定义标题栏,如下所示:
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.title_bar);
title_bar.xml:
我不明白这是做什么的getWindow.setFeatureIntWindow.FEATURE\u CUSTOM\u TITLE,R.layout.TITLE\u bar;你是说用一个还是另一个?是title_bar.xml还是我刚才指定的?如果你能解释得更多,那就太好了。不,我不是说多使用一个标题栏。我的意思是使用自定义标题栏而不是系统默认标题栏。创建自定义标题栏时,需要将xml布局作为第二个参数。在此布局中,您可以按照需要在中间对齐文本,右或左…对于title_bar.xml,在您的res/layout文件夹中添加新的xml文件,并将您的xml放入标题栏。如果您有任何问题,请询问meAh,我无法使其工作,如果您可以,您可以使用teamviewer me吗?我下载了它并将其放入2.3.3,它有一个错误,我通过删除@override来修复它。然后我运行它。但是最顶端的标题——小灰条——并没有居中。这正是我想强调的。
<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/centertxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="title bar"
android:layout_centerInParent="true"
android:layout_marginLeft="5dip"
android:textStyle="bold"
android:textColor="#ffffff"
android:textSize="20sp"
/>
</RelativeLayout >