【发布时间】:2016-11-10 20:17:49
【问题描述】:
想要创建自定义 ActionBar,应用名称位于其中心,但仍与左侧对齐。这是 custom_actionbar.xml
的 xml<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@color/transparent">
<TextView
android:id="@+id/nav_bar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@color/transparent"
android:singleLine="true"
android:textColor="@color/sue_green"
android:text="@string/app_name"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
</RelativeLayout>
这里是关于创建 Activity:
public class DeviceOverviewActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
setTheme(R.style.Theme_SUE);
setContentView(R.layout.activity_device_overview);
final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.custom_actionbar, null);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(v);
}
...
}
你能告诉我我做错了什么吗? 谢谢
【问题讨论】:
-
尝试使用 LinearLayout,并删除此行 android:layout_centerInParent="true"
标签: android android-layout textview