0
我得到了按鈕欄在整個佈局和活動中工作。當我按下不同的按鈕並在手機上按下「返回」時,我得到一個「交換」動畫,讓我回到所有以前的活動/佈局。按鈕工作正常,我認爲它與意圖有關我的Java。在這種情況下,ViewFlipper會是更好的選擇嗎?或者是否可以使用Intent刪除它。由於交換動畫顯示何時進入不同的佈局/活動。按鈕欄
buttonbar.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:shrinkColumns="*"
android:stretchColumns="*"
android:background="#6B1414">
<TableRow
android:id="@+id/tableRow1"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<Button
android:id="@+id/btn1"
android:text="@string/Str"
android:textStyle="bold"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:padding="18dip"
android:layout_weight="1"
android:background="#424242"
android:textColor="#ffffff"
android:gravity="center"/>
<Button
android:id="@+id/btn2"
android:text="@string/Agl"
android:textStyle="bold"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:padding="18dip"
android:layout_weight="1"
android:background="#424242"
android:textColor="#ffffff"
android:gravity="center"/>
<Button
android:id="@+id/btn3"
android:text="@string/Int"
android:textStyle="bold"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:padding="18dip"
android:layout_weight="1"
android:background="#424242"
android:textColor="#ffffff"
android:gravity="center"/>
<Button
android:id="@+id/btn4"
android:text="@string/Misc"
android:textStyle="bold"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#424242"
android:textColor="#ffffff"
android:padding="18dip"/>
</TableRow>
</TableLayout>
MainActivity.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn1 =(Button)findViewById(R.id.btn1);
Button btn2 =(Button)findViewById(R.id.btn2);
Button btn3 =(Button)findViewById(R.id.btn3);
Button btn4 =(Button)findViewById(R.id.btn4);
btn1.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent();
myIntent = new Intent(getApplicationContext(), MainActivity.class);
myIntent.setAction(Intent.ACTION_VIEW);
myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
setContentView(R.layout.activity_main);
startActivityForResult(myIntent, 0);
}
});
btn2.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent();
myIntent = new Intent(getApplicationContext(), MainAgil.class);
myIntent.setAction(Intent.ACTION_VIEW);
myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
setContentView(R.layout.agil_main);
startActivityForResult(myIntent, 0);
}
});
btn3.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent();
myIntent = new Intent(getApplicationContext(), MainInt.class);
myIntent.setAction(Intent.ACTION_VIEW);
myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
setContentView(R.layout.int_main);
startActivityForResult(myIntent, 0);
}
});
btn4.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent();
myIntent = new Intent(getApplicationContext(), MainMisc.class);
myIntent.setAction(Intent.ACTION_VIEW);
myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
setContentView(R.layout.misc_main);
startActivityForResult(myIntent, 0);
}
});
}}
謝謝,我讀了指導,但我很困惑如何做到這一點有一個按鈕欄來實現。任何例子?提前致謝。 – DuckiesUnite 2013-03-22 20:46:30
使用帶有按鈕欄和上方按鈕的佈局,或者任何你想要的地方,放置一個框架佈局或片段本身。那個鏈接就是一個很好的例子。請耐心等待並閱讀。 :)不要忘記標記這個答案爲接受和正確的。對我好。 – Moesio 2013-03-22 20:54:50