android自定义标题栏
来源:互联网 发布:淘宝软文大全 编辑:程序博客网 时间:2024/05/07 15:07
android自定义标题栏思路:
1.在layout中添加标题栏的布局文件title(具体布局自己设置)
2.自定义控件类(继承自自己标题栏布局文件的布局类):
使用LayoutInflater.from(context).inflate(R.layout.title,this);
来用布局文件进行填充
之后写下自己标题栏的逻辑,比如按钮的点击事件等等
3.在要调用自定义标题栏的布局文件中使用包名.自定义标题栏类名的方式来使用自定义标题栏
其他小知识:
1.使用自定义标题栏时要隐藏默认的标题栏:
ActionBar actionBar=getSupportActionBar();
if(actionBar!=null){
actionBar.hide();
}
其中调用了getSupportActionBar()方法来获得ActionBar的实例。
2.在标题栏类中设置按钮的点击事件用于返回(关闭当前活动):
((Activity)getContext()).finish();
3.设置监听器的两种方法:
(1)直接使用匿名类
在onCreate()方法中:
Button btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
点击事件的逻辑;
}
});
(2)实现监听器接口:
首先实现接口
public class MainActivity extends AppCompatActivity implements View.OnClickListener
其次
得到按钮对象 Button button = (Button) findViewById(R.id.button);
设置监听器 button.setOnClickListener(this);
重写点击方法:
@Overridepublic void onClick(View v) { switch (v.getId()) { case R.id.button: 点击事件的逻辑; break; default: break; } }
4.文字大小使用单位:sp
控件大小使用单位:dp
- android自定义标题栏progressBar
- Android自定义标题栏
- 自定义android标题栏
- android实现自定义标题栏
- Android自定义标题栏
- Android 自定义标题栏
- Android 自定义标题栏
- Android自定义标题栏
- Android自定义标题栏
- android之自定义标题栏
- Android自定义标题栏
- Android 自定义标题栏运用
- Android 自定义标题栏
- android ListView+自定义标题栏
- Android 自定义标题栏
- Android:自定义标题栏
- Android Actionbar自定义标题栏
- 自定义Android标题栏TitleBar
- android Studio
- Struts+Mybatis PageHelper实现分页
- SpringAOP使用注意事项
- hdu2094 产生冠军
- Quiz项目布局部分,定义横屏时的布局
- android自定义标题栏
- 回顾大一·C语言编程4.1(2)
- 一种SPA(单页面应用)架构
- Spring 加载、解析applicationContext.xml 流程
- 引入第三方类库grafika-master
- spring中 throw new Exception()导致事务不起作用
- 欢迎使用CSDN-markdown编辑器
- F. Cities Excursions(倍增)
- angularJs的学习(2)