【发布时间】:2014-09-23 18:36:12
【问题描述】:
您好,我正在开发演示应用程序,我需要在其中心设置 ActionBar 的标题。我尝试了一些对我不起作用的 SO 帖子。我正在使用 Android 4.3 手机。
https://stackoverflow.com/a/21770534/2455259 , https://stackoverflow.com/a/19244633/2455259
但没有什么对我有用。有没有办法使用 appcompat 将 ActionBar 的标题设置为 Android 中心?
我正在这样做,但标题仍然在左侧。
center_action_bar_title.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
活动中
TextView customView = (TextView)
LayoutInflater.from(getActivity()).inflate(R.layout.center_action_bar_title,
null);
ActionBar.LayoutParams params = new
ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
customView.setText(text);
((ActionBarActivity)getActivity()).getSupportActionBar().setCustomView(customView, params);
【问题讨论】:
标签: android android-actionbar android-appcompat android-actionbar-compat