android主题跟样式

android主题跟样式

样式主要用于很多界面用于相同的风格

1.在values下建立一个样式,名称可以任意,

2.在Resources点击add添加一个name跟parent,在添加item就是我们显示的具体内容

3,在布局xml中引用style="@style/text_content_style"这里的名称就是我们刚才定义的

样式跟样式可以继承的

在定义样式时在parent中添加我们要继承的样式,然后在<item>标签中加入我们要更改的内容

主题跟样式创建步骤差不多,不同的是样式只能作用于某一个控件上,但是主题可以作用于一个activity上,在使用时多了一步配置,在一个activity中定义一个标签android:theme="@style/activity_bg_theme"可以引用我们定义的主题了

如果把主题放在application下那么这个application的activity都会去继承这个主题

在代码中也可以动态更换主题,在activity中调用setTheme(主题)就可以引入我们想要的主题了

 

黑名单:只拦截黑名单里面的电话跟短信,监听系统的电话跟短信,如果发现是黑名单就立刻拦截

 

桢布局:<FrameLayout>

在要隐藏和显示的组件里添加android:visibility="invisible"

在代码中判断条件,如果满足条件设置可见

iv_callsms_hint.setvisibility(View.VISIBLE);

 

设置点击一个条目弹出一个悬浮菜单(上下文菜单),这个菜单是长按的才能显示的

在android的dev Guide-->User interface-->Menus-->create a contextMenu这上面有详细的步骤说明:

1.view对象注册一个上下文对象(listView)

1. registerForContextMenu(getListView());

2. 2.重写onCreatecontextMenu()方法

3. For example, here's an onCreateContextMenu() that uses the context_menu.xml menu resource:

@Override

public void onCreateContextMenu(ContextMenu menu, View v,

ContextMenuInfo menuInfo) {

super.onCreateContextMenu(menu, v, menuInfo);

MenuInflater inflater = getMenuInflater();

inflater.inflate(R.menu.context_menu, menu);

}

3.重写onContextItemSelected()方法条目响应的事件

Then when the user selects an item from the context menu, the system calls onContextItemSelected(). Here is an example of how you can handle selected items:

@Override

public boolean onContextItemSelected(MenuItem item) {

AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

switch (item.getItemId()) {

case R.id.edit:

editNote(info.id);

return true;

case R.id.delete:

deleteNote(info.id);

return true;

default:

return super.onContextItemSelected(item);

}

}

//得到点击的listView的信息可以用以下这代码:

iv_call_sms_safe.getItemAtPostition((int)info.id);info是被点击的条目的信息

 

如果在listView的显示界面中要删除一条记录,我们使用如下代码:

blacknumbers.remove(blacknumber);//这个代码是从view的集合中去除掉这个记录

adapter.notifyDataSetChanged()//这个是通知数据适配器更新里面的内容,只会更新当前的view内容,所以页面还是停留在刚才的位置

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章