【问题标题】:Rendering issue while using action bar使用操作栏时出现渲染问题
【发布时间】:2016-05-31 15:48:51
【问题描述】:

当我在onCreate 方法中编写以下代码时:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Get a support ActionBar corresponding to this toolbar
        ActionBar ab = getSupportActionBar();

        // Enable the Up button
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setTitle("Vodafone-Dongles");
    }
}

我明白了:

否则就OK了,显示action bar的默认标题。

为什么我会得到它?

【问题讨论】:

标签: android android-actionbar rendering android-appbarlayout appcompatactivity


【解决方案1】:

你应该使用工具栏而不是操作栏:-

插入您的活动:-

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

在布局中包含以下内容:-

    <Include layout="@layout/app_bar_main"
    android:layout_height="50dp"
    android:layout_width="match_parent" ></Include>

app_bar_main.xml

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/green"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    • 2011-09-15
    • 1970-01-01
    • 2023-03-19
    • 2016-01-25
    • 2013-07-30
    • 1970-01-01
    相关资源
    最近更新 更多