2021-10-09

APP门户界面设计(微信界面)

技术:使用布局(layouts)和分段(fragment),对控件进行点击监听;
布局设计
 此仿微信界面分为三部分,标题栏,中间内容页面,底部栏,故分部分进行设计。
标题栏

添加一个TextView,填入文字,定义大小和颜色,设置背景颜色,有关于文字居中,我们要修改和添加一些配置信息。
 在linearlayout中,我们修改gravity所对应的配置信息为center
.java文件编写
 由于布局文件以及设置编写好了,我们需要编写控制代码逻辑的Java文件
这里最重要的是Fragment,这里我们需要对每一个Fragment(对应一个xml布局文件)新建一个Fragment类
ChatFragment.java
FriendsFragment.java
BookFragment.java
SettingFragment.java
1.new出各个界面(Fragment)的对象,还有有一个FragmentManager管理所有的Fragment

private Fragment chatFragment = new ChatFragment();
private Fragment friendsFragment = new FriendsFragment();
private Fragment commFragment = new CommFragment();
private Fragment settingFragment = new SettingFragment();

并且创建一个Fragment管理变量`

private FragmentManager fragmentManager;

新建一个initFragment函数用以给Fragment页面初始化,在此函数中,将此前定义个4个Fragment变量使用fragmentManager添加到activity_mainw文件的Framelayout布局中

private void initFragment(){
fragmentManager = getSupportFragmentManager();
FragmentTransaction
transaction = fragmentManager.beginTransaction();
transaction.add(R.id.content,chatFragment);
transaction.add(R.id.content,friendsFragment);
transaction.add(R.id.content,commFragment);
transaction.add(R.id.content,settingFragment);
transaction.commit();
}

对bottom.xml下的4个imagebutton控件和4个linearlayout控件建立8个变量
private LinearLayout chatLayout;
private LinearLayout friendsLayout;
private LinearLayout commLayout;
private LinearLayout settingLayout;

编写initview函数,将此8个变量和bottom中的8个控件联系起来

private void initView(){
chatLayout = findViewById(R.id.chatLayout);
friendsLayout = findViewById(R.id.friendsLayout);
commLayout = findViewById(R.id.commLayout);
settingLayout = findViewById(R.id.settingLayout);

    chatImageButton = findViewById(R.id.chatImageButton);
    friendsImageButto = findViewById(R.id.friendsImageButton);
    commImageButton = findViewById(R.id.commImageButton);
    settingImageButton=findViewById(R.id.settingImageButton);

    chatText = findViewById(R.id.chatText);
    friendsText = findViewById(R.id.friendsText);
    commText = findViewById(R.id.commText);
    settingText = findViewById(R.id.settingText);
}

设置监听程序

public class MainActivity extends AppCompatActivity implements View.OnClickListener
@SuppressLint(ResourceAsColor)
private void resetBtn(){
chatImageButton.setImageResource(R.drawable.chat);
friendsImageButton.setImageResource(R.drawable.friends);
commImageButton.setImageResource(R.drawable.comm);
settingImageButton.setImageResource(R.drawable.setting);

    chatText.setTextColor(this.getResources().getColor(R.color.nopickText));
    friendsText.setTextColor(this.getResources().getColor(R.color.nopickText));
    commText.setTextColor(this.getResources().getColor(R.color.nopickText));
    settingText.setTextColor(this.getResources().getColor(R.color.nopickText));
}

实现效果:
在这里插入图片描述
已将代码上创git仓库
代码仓库

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值