本文共 1322 字,大约阅读时间需要 4 分钟。
今天简单写了一个底部导航栏,封装了一个库,用法比较简单
package com.kongqw.kqwbottomnavigation;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Toast;import com.kongqw.bottomnavigationlib.KqwBottomNavigation;import com.kongqw.bottomnavigationlib.OnBottomNavigationSelectedListener;import com.kongqw.bottomnavigationlib.ToastUtil;public class MainActivity extends AppCompatActivity implements OnBottomNavigationSelectedListener { private KqwBottomNavigation mKqwBottomNavigation; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mKqwBottomNavigation = (KqwBottomNavigation) findViewById(R.id.kbn); mKqwBottomNavigation.setBottomNavigationSelectedListener(this); } @Override public void onValueSelected(int index) { ToastUtil.show(this, "index = " + index); }}
public void setBottomNavigationSelectedListener(OnBottomNavigationSelectedListener l)
点击后的回调如下
@Overridepublic void onValueSelected(int index) { ToastUtil.show(this, "index = " + index);}
public void setBottomNavigationClick(int index)
我这里为了方便,只设定了0~3,依次代表底部四个按钮,可以使用枚举,只允许传入特定的值