gpt4 book ai didi

android - 工具栏在布局中不可见

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:57:45 25 4
gpt4 key购买 nike

下面是我的布局,运行时toolbar根本不可见,tabview上的两个tab占据了整个屏幕。在 AndroidStudio 的预览中,我确实看到了 ActionBar,因为我希望它位于顶部。我错过了什么?

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/c">


<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar2"
android:layout_height="wrap_content"
android:layout_width="fill_parent"

android:background="?attr/colorPrimary"
android:layout_marginBottom="10dp"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" />


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/c2">


<android.support.design.widget.TabLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/tabs"
app:layout_scrollFlags="scroll|enterAlways"/>
</RelativeLayout>




<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">

</android.support.v4.view.ViewPager>

这是我使用此布局的 Activity :

public class TabletGallery extends AppCompatActivity implements ActionBar.TabListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //To change body of overridden methods use File | Settings | File Templates.
setContentView(R.layout.tablet_gallery);

// Initilization

toolbar = (Toolbar) findViewById(R.id.my_toolbar2);
setSupportActionBar(toolbar);
viewPager = (ViewPager) findViewById(R.id.pager);
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(mAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));

最佳答案

改为使用 LinearLayout 作为根布局。

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/c">


<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar2"
android:layout_height="wrap_content"
android:layout_width="fill_parent"

android:background="?attr/colorPrimary"
android:layout_marginBottom="10dp"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" />

<android.support.design.widget.TabLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/tabs"
app:layout_scrollFlags="scroll|enterAlways"/>


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/c2">

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">

</android.support.v4.view.ViewPager>

</RelativeLayout>






</LinearLayout>

关于android - 工具栏在布局中不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30949209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com