最初にツールバーがあり、リサイクルビューを追加しましたが、ツールバーは表示されなくなりました。私はツールバーを表示するためにすべてを試みたが、私はいつも失敗した。どのようにツールバーを戻すことができるのか教えていただけますか?前もって感謝します。ここで Androidでツールバーが表示されない
public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener{
private Toolbar mToolbar;
private FragmentDrawer drawerFragment;
private RecyclerView recyclerView;
private IsAdapter isAdapter;
private List<Is> isList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
isList = new ArrayList<>();
isAdapter = new IsAdapter(this, isList);
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(this, 1);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.addItemDecoration(new GridSpacingItemDecoration(1, dpToPx(10), true));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(isAdapter);
prepareIsler();
drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
drawerFragment.setDrawerListener(this);
getSupportActionBar().setTitle("TTT");
// display the first navigation drawer view on app launch
displayView(0);
}
がレイアウトコードです: はここに私のJavaコードである
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<!-- <include
android:id="@+id/toolbar"
layout="@layout/toolbar" /> -->
</LinearLayout>
<FrameLayout
android:id="@+id/container_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<fragment
android:id="@+id/fragment_navigation_drawer"
android:name="com.example.neozeka1.dts2.FragmentDrawer"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"
tools:layout="@layout/fragment_navigation_drawer" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="info.androidhive.cardview.MainActivity"
tools:showIn="@layout/activity_main">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:scrollbars="vertical" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
'DrawerLayout'に1つのコンテンツ' View'が必要です。だから、あなたは物事を手配することを意味しますが、引き出しではないものはすべて、あなたの引き出しの上の一つの 'ViewGroup'にあるべきです。'。 –
@MikeMあなたは例を示していただけますか?ありがとうございました – jason
本当に、あなたがしようとしていることを私は伝えることはできません。 'RecyclerView'がメインコンテンツである場合、' container_toolbar'の下にある最も外側の 'LinearLayout'の内側に移動し、' RelativeLayout'と 'FrameLayout'を取り除きます。他に何も入っていない場合、 'container_toolbar'''DinearLayout'も捨てることができます。 –