2016-05-04 14 views
1

私は断片を保持するためのアクティビティを作成しました。実行時またはXMLプレビューでツールバーに表示されるアップボタンはありません。Android Activity Toolbar上のボタンが表示されない

これは私がすべて正しいライブラリ(AppCompatActivity)を使用していた私は活動

Toolbar mToolbar = (Toolbar) findViewById(R.id.category_toolbar); 
setSupportActionBar(mToolbar); 

if(getSupportActionBar() != null){ 
    getSupportActionBar().setTitle("Test"); 
    getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true); 
    getSupportActionBar().setDisplayShowHomeEnabled(true); 
} 

にツールバーを追加するために使用されるコードです。このアクティビティには断片とそれが表示されませんでした。私は、マニフェストファイルに

<activity android:name=".TestActivity" 
        android:parentActivityName=".MainActivity"> 

     </activity> 

を親アクティビティをも設定している活動

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/category_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     style="@style/toolbar"> 
    </android.support.v7.widget.Toolbar> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/fragment_container"> 

    </LinearLayout> 

</LinearLayout> 

ため

XMLは、私はそれを動作させるために追加する必要がある何か他のものはありますか?

おかげ

+0

を使用する場合

setDefaultDisplayHomeAsUpEnabled(true)は動作しますが、何もすぐにこれで間違っているようです。 'getSupportActionBar()。setDisplayHomeAsUpEnabled(true);'あなたが必要なものすべてにする必要があります –

+0

ありがとう@ cricket_007、私は間違ったメソッドを使用しましたhaha – Excellent

答えて

1

あなたはあなたの問題を解決するだろう、というよりもsetDefaultDisplayHomeAsUpEnabled(true)setDisplayHomeAsUpEnabled(true)を使用して、ベースの活動としてAppCompatActivityを使用しているので。あなたは、一般的フラグメントコンテナのFrameLayoutsを使用ActionBarActivity.

+0

ありがとう!それは今働いている。 – Excellent

+0

@それはあなたを働いている嬉しい:) – Sac

関連する問題