我得到了按钮栏,可以在整个布局和活动中使用。当我按下一个不同的按钮并按下我手机上的“后退”时,我会收到一个“交换”动画,让我回到之前的所有活动/布局..按钮工作正常,我认为它与意图有关我的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);
}
});
}}
答案 0 :(得分:0)
您正在开始新的活动,并且正在推动每个新活动,例如堆栈。后退按钮只是做它的实际工作,回到最后的活动。如果您真的想要维护按钮栏,请尝试片段
http://developer.android.com/guide/components/fragments.html