第一个界面框架
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new Thread(){ public void run() { SystemClock.sleep(4000); //停留四秒 // 跳转 Intent intent = new Intent(MainActivity.this,MainActivity2.class); startActivity(intent); finish(); //关闭自己,因为跳转到第二个页面后如果返回,不关闭第一个页面,页面还会存在 }; }.start(); } } 第二个界面 /** * 输入页面 * @author admin * */ public class MainActivity2 extends Activity{ private static final String TAG = "MainActivity2"; private EditText filmname; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); filmname = (EditText) findViewById(R.id.et_name); button = (Button) findViewById(R.id.button); filmname.setText("猫咪"); //这里的内容定死了,其实应该在应用上输入的··· } public void search (View view){ String name = filmname.getText().toString(); //获取用户输入 if (TextUtils.isEmpty(name)) { Toast.makeText(MainActivity2.this, "请输入影视名", 0).show(); return; } byte[] by = name.getBytes(); //识别二进制,转换成数组 int number = 0; for (byte b : by) { number += Math.abs(b & 0xff); } Log.d(TAG, number/100+50+""); String str = ""; if (number>100) { str = "电影"; }else if (number>70) { str = "电视剧"; }else if (number>40) { str = "动漫"; } Intent intent = new Intent(MainActivity2.this,ThirdActivity.class); //跳转 intent.putExtra("搜索结果", str); //传递数据 startActivity(intent); } }第三个界面
/** * 搜索结果界面 * @author admin */ public class ThirdActivity extends Activity{ private TextView show; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.item_picture); show = (TextView) findViewById(R.id.show); Intent intent = getIntent(); String result = intent.getStringExtra("搜索结果"); //接收数据 show.setText(result); } } 注意:两个Activity 都要在清单中注册,同一个包下面可以不用再写包名另外,其他两个Activity都要新建布局
根据需求,如果总是要改换布局,就可以在styles的样式表中设置布局(res-----value-----styles)
<style name = "TextStyle"> <item name="android:textColor">#00bfff</item> <item name="android:textSize">25sp</item> <item name="android:background">#fffff0</item> <item name="android:layout_gravity">center_horizontal</item> </style> <style name="TextStyle2" parent="TextStyle"> <item name="android:textColor">#f08080</item> </style>
传送方
Intent intent = new Intent(MainActivity.this,SecondActivity.class); Computer computer = new Computer("花语月",16); intent.putExtra("computer", computer); startActivity(intent);接收方
Computer compSeria = (Computer) intent.getSerializableExtra("computer"); text.setText(compSeria.toString());传送方
Bundle bundle = new Bundle(); Computer computer = new Computer("android studio",16); bundle.putSerializable("computer", computer); intent.putExtra("bundle", bundle);接收方 Intent intent = getIntent(); //获取数据 Bundle bund = intent.getBundleExtra("bundle"); //获取bundle Computer compSeria = (Computer) bund.getSerializable("computer"); //强转类型