微信按钮的插件(快捷版)

博客内容提及了导依赖,这在信息技术开发中是常见操作,依赖的导入有助于使用已有的代码库和功能,提高开发效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、导依赖

compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar'
二、在Macitivity的Xml中
复制即可,但有的地方会报红,报红后先提成到RelativeLayout中,而后CTRL、ALT+空格键,选择第一个!

 
<<span style="color:#000080;font-weight:bold;">RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tl="http://schemas.android.com/apk/res-auto"
tools:context="com.example.asus.androidfire.MainActivity">

<<span style="color:#000080;font-weight:bold;">android.support.v4.view.ViewPager
android:id="@+id/vp_2"
android:layout_above="@+id/tl_2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<<span style="color:#000080;font-weight:bold;">com.flyco.tablayout.CommonTabLayout
android:id="@+id/tl_2"
android:layout_width="match_parent"
android:layout_height="54dp"
android:layout_alignParentBottom="true"
android:background="#ffffff"
tl:tl_iconHeight="23dp"
tl:tl_iconWidth="23dp"
tl:tl_indicator_color="#ffff00"
tl:tl_indicator_height="0dp"
tl:tl_textSelectColor="#ffff00"
tl:tl_textUnselectColor="#66000000"
tl:tl_textsize="12sp"
tl:tl_underline_color="#DDDDDD"
tl:tl_underline_height="1dp"/>

</<span style="color:#000080;font-weight:bold;">RelativeLayout>
三、Mactivity中
public class MainActivity extends AppCompatActivity {

private ViewPager vp_2;
private CommonTabLayout tl_2;
private ArrayList mFragments = new ArrayList<>();

//设置标题

private static final String[] mTitles = {"微信", "通讯录", "发现", "我"};

//设置选中图标

private static final int[] mIconSelectIds = {R.drawable.ic_home_selected,
R.drawable.ic_care_selected, R.drawable.ic_girl_selected, R.drawable.ic_video_selected};

//设置未选中图标

private static final int[] mIconUnselectIds = {R.drawable.ic_home_normal,
R.drawable.ic_care_normal, R.drawable.ic_girl_normal, R.drawable.ic_video_normal};
private ViewPager mViewPager;

private CommonTabLayout mTabLayout_2;
private ArrayList mTabEntities = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
for (String title : mTitles) {
mFragments.add(new BlankFragment());
}


for (int i = 0; i < mTitles.length; i++) {
mTabEntities.add(new TabEntity(mTitles[i], mIconSelectIds[i], mIconUnselectIds[i]));
}
mTabLayout_2.setTabData(mTabEntities);
mViewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
}

private void initView() {
mViewPager = (ViewPager) findViewById(R.id.vp_2);
mTabLayout_2 = (CommonTabLayout) findViewById(R.id.tl_2);
}

private class MyPagerAdapter extends FragmentPagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}

@Override
public int getCount() {
return mFragments.size();
}

@Override
public CharSequence getPageTitle(int position) {
return mTitles[position];
}

@Override
public Fragment getItem(int position) {
return mFragments.get(position);
}
}
}
四、创建一个工具类
public class TabEntity implements CustomTabEntity {
public String title;
public int selectedIcon;
public int unSelectedIcon;

public TabEntity(String title, int selectedIcon, int unSelectedIcon) {
this.title = title;
this.selectedIcon = selectedIcon;
this.unSelectedIcon = unSelectedIcon;
}

@Override
public String getTabTitle() {
return title;
}

@Override
public int getTabSelectedIcon() {
return selectedIcon;
}

@Override
public int getTabUnselectedIcon() {
return unSelectedIcon;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值