钢镚儿开发第三、第四天
package com.example.myapplicationgb; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; import android.os.SystemClock; import android.view.View; import android.widget.ImageButton; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; public class MainActivity extends AppCompatActivity implements View.OnClickListener { private static final String TAG = "MainActivity"; private FragmentTransaction transaction; private FragmentManager manager; private ImageButton tabmingxi; private ImageButton tabadd; private ImageButton tabjizhang; private ImageButton tabUser; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent intent = new Intent(this, AutoReceiver.class); intent.setAction("VIDEO_TIMER"); // PendingIntent这个类用于处理即将发生的事情 PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent, 0); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); // AlarmManager.ELAPSED_REALTIME_WAKEUP表示闹钟在睡眠状态下会唤醒系统并执行提示功能,该状态下闹钟使用相对时间 // SystemClock.elapsedRealtime()表示手机开始到现在经过的时间 am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), 10 * 1000, sender); //初始化控件 initView(); manager = getSupportFragmentManager(); transaction = manager.beginTransaction(); //将主页添加到第一个fragment中,即默认fragment Fragment fragment_index = new FirstFragment(); transaction.add(R.id.fragment_container,fragment_index); transaction.commit(); } private void initView() { tabmingxi = (ImageButton)this.findViewById(R.id.txt_mingxi); tabadd = (ImageButton)this.findViewById(R.id.txt_add); tabjizhang= (ImageButton)this.findViewById(R.id.txt_jizhang1); tabUser=this.findViewById(R.id.txt_user); tabmingxi.setOnClickListener(this); tabadd.setOnClickListener(this); tabjizhang.setOnClickListener(this); tabUser.setOnClickListener(this); } @Override public void onClick(View v) { transaction = manager.beginTransaction(); resetImgs(); switch (v.getId()){ //通过switch判断用哪个fragment替换当前的fragment case R.id.txt_mingxi: Fragment firstfragment = new FirstFragment(); transaction.replace(R.id.fragment_container,firstfragment); tabmingxi.setImageResource(R.mipmap.mingxi1); //tabmingxi.setImageResource(R.mipmap.mingxi); break; case R.id.txt_add: Fragment erfragment = new erFragment(); transaction.replace(R.id.fragment_container,erfragment); tabadd.setImageResource(R.mipmap.tianjia1); break; case R.id.txt_jizhang1: Fragment sanfragment = new sanFragment(); transaction.replace(R.id.fragment_container,sanfragment); tabjizhang.setImageResource(R.mipmap.a_tubiao); break; case R.id.txt_user: Fragment sifragment = new siFragment(); transaction.replace(R.id.fragment_container,sifragment); tabUser.setImageResource(R.mipmap.women1); break; } transaction.commit(); } private void resetImgs() { tabmingxi.setImageResource(R.mipmap.mingxi); tabadd.setImageResource(R.mipmap.tianjia); tabjizhang.setImageResource(R.mipmap.a_tubiao); tabUser.setImageResource(R.mipmap.women); } }
这两天是周六日,主要还是进行我的界面的编写,现在我的界面有了雏形,也可以在手机上面进行运行;
但是非常的丑陋,还需要我进行改善和完善;这两天大部分的时间都在编写安卓,参考网上人家的界面,发现自己的审美还有待提升;
接下来的时间是要完善界面和帮助我的队友进行他们所负责的那部分内容;