2016-11-04 41 views
0

進出口使用StaggeredGridView添加工具欄和我想補充工具欄StaggeredGridView,這是我的活動:如何StaggeredGridView活動

public class CategoryCarActivity extends AppCompatActivity implements AbsListView.OnScrollListener, AbsListView.OnItemClickListener { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_sgv); 

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

    setSupportActionBar(toolbar); 
    // getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    ... 
} 

activity_sgv.xml

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

<com.etsy.android.grid.StaggeredGridView 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/grid_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
app:item_margin="8dp" 
app:column_count="@integer/grid_column_count" /> 

<android.support.v7.widget.Toolbar 
android:id="@+id/toolbar" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="?attr/colorPrimary" 
android:minHeight="?attr/actionBarSize" 
android:theme="@style/ThemeOverlay.AppCompat.Dark" 
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
app:titleTextColor="@android:color/holo_blue_bright" /> 

<TextView 
android:id="@+id/text_view" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_margin="@dimen/activity_horizontal_margin" 
android:gravity="center" /> 
</LinearLayout> 

它不會顯示工具欄g雖然我檢查了Logcat,並沒有發生任何錯誤。

如何解決這個問題Toobar顯示?謝謝 !

回答

0

您無法將ToolBar看作其包裝在StaggeredGridView下面。

如何解決:

試試這個:

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

<android.support.v7.widget.Toolbar 
android:id="@+id/toolbar" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="?attr/colorPrimary" 
android:minHeight="?attr/actionBarSize" 
android:theme="@style/ThemeOverlay.AppCompat.Dark" 
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
app:titleTextColor="@android:color/holo_blue_bright" /> 

<com.etsy.android.grid.StaggeredGridView 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/grid_view" 
android:layout_below="@id/toolbar" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
app:item_margin="8dp" 
app:column_count="@integer/grid_column_count" /> 



<TextView 
android:id="@+id/text_view" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_margin="@dimen/activity_horizontal_margin" 
android:gravity="center" /> 
+0

馬麗娟!它顯示,但後退按鈕不顯示 – luongkhanh

+0

setSupportActionBar(toolbar); getSupportActionBar()。setDisplayHomeAsUpEnabled(true); getSupportActionBar()。setDisplayShowHomeEnabled(true); –

+0

如果確實有幫助,請將其標記爲答案,XML文件中定義的後退按鈕在哪裏? – OBX