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內容,所以頁面還是停留在剛纔的位置