安卓移动开发技术————微信界面的设计
实验要求
类微信界面设计请根据课堂展示结果设计APP门户界面,包含4个tab切换效果。
实验过程
1、目录结构:
2、在MainActivity.java中完善逻辑控制,核心代码如下:
下面展示一些 内联代码片
。
package com.example.mywechat;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import java.lang.ref.PhantomReference;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private LinearLayout getmTabWeixin;
private LinearLayout getmTabFrd;
private LinearLayout getmTabAddress;
private LinearLayout getmTabSettings;
private ImageButton getMlmgWeixin;
private ImageButton getMlmgFrd;
private ImageButton getMlmgAddress;
private ImageButton getMlmgSettings;
private Fragment mTab01 = new weixinFragment();
private Fragment mTab02 = new frdFragment();
private Fragment mTab03 = new contactFragment();
private Fragment mTab04 = new settingsFragment();
private FragmentManager fm = getFragmentManager();
private LinearLayout mTabWeixin;
private LinearLayout mTabFrd;
private LinearLayout mTabAddress;
private LinearLayout mTabSettings;
private ImageButton mlmgWeixin;
private ImageButton mlmgFrd;
private ImageButton mlmgAddress;
private ImageButton mlmgSettings;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
initView();
initFragment();
initEvent();
selectfragmengt(0);
}
private void initFragment(){
fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.add(R.id.id_content,mTab01);
transaction.add(R.id.id_content,mTab02);
transaction.add(R.id.id_content,mTab03)