1
我是Android應用開發和使用Android studio的新手。我想在TextBar中放置一個Textview。這裏是我的工具欄的XML文件的代碼:ToolBar中的TextView在setDisplayHomeAsUpEnabled上正確移動(true)
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF5722"
android:elevation="4dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Holler"
android:textColor="@android:color/white"
android:textStyle="bold|italic"
android:textSize="30dp"
android:layout_gravity="center"
android:id="@+id/toolbar_title"
android:gravity="center"
/>
</android.support.v7.widget.Toolbar>
在我的第一個活動是露出如預期中的中心。但是當我啓動新的Activity時,TextView正在向右移動。這是我FirstActivity的代碼:
toolbarHome = (Toolbar) findViewById(R.id.tool_bar_home); // Attaching the layout to the toolbar object
setSupportActionBar(toolbarHome);
final android.support.v7.app.ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeAsUpIndicator(R.mipmap.ic_launcher);
actionBar.setDisplayHomeAsUpEnabled(true);
}
如果您需要更多的代碼,請讓我知道。
你解決這個問題 –
@RaguSwaminathan不..還沒有。你能幫我嗎?... – Rakesh
是的。您是否使用工具欄作爲單獨的xml並設置自定義視圖或將其作爲頂部活動的一部分添加 –