我正在開發一個關於音樂的Android應用程序。在這個應用程序中,我有兩個片段:PopFragment e GenresFragment。
在PopFragment的XML文件中調用fragment_pop.xml,我有一個工具欄,它帶有一個返回到GenresFragment的後退箭頭。
我的工具欄的代碼是這樣的:如何處理後退箭頭點擊?
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<include
android:layout_height="wrap_content"
android:layout_width="match_parent"
layout="@layout/toolbar_layout"
/>
</android.support.design.widget.AppBarLayout>
<ImageButton
android:id="@+id/arrowPop"
android:layout_width="54dp"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow_back_black_24dp"
style="?android:attr/borderlessButtonStyle"
/>
在PopFragment的Java文件名爲PopActivity,我有一些代碼,但它不工作。
我有這樣的代碼:
public class PopActivity extends AppCompatActivity implements View.OnClickListener {
public PopActivity() {
// Required empty public constructor
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_pop);
Toolbar toolbar = (Toolbar)findViewById(R.id.toolBar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
ImageButton backBtn = (ImageButton)findViewById(R.id.arrowPop);
}
@Override
public void onClick (View view) {
Intent i = new Intent();
switch (view.getId()) {
case R.id.arrowPop:
break;
}
}
你能幫助我嗎?
謝謝