1. 簡介
因?yàn)樽罱幚淼腶ndroid9.0的代碼缚柳,在packages\apps\Settings下面的settings是手機(jī)版的屋确,無法使用遙控器進(jìn)行操作撮奏。
2. settings顯示圖片
下面是修改后的圖片
3.增加焦點(diǎn)事件
首先找到布局隅要,布局我們可以通過grep添加語言去找到語言設(shè)置
然后了解到整個布局是recyclerview的控件寫法
那么我們找到recyclerview的adapter报账,然后再通過adapter尋找到布局研底,對item的layout設(shè)置一個背景圖和焦點(diǎn)。
布局文件:packages/apps/Settings/res/layout/locale_drag_cell.xml
<com.android.settings.localepicker.LocaleDragCell xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/local_language"
android:layout_width="match_parent"
android:layout_height="wrap_content"
//start 增加下面兩行
android:focusable="true"
android:background="@drawable/local_bg_focus"
//end
android:layoutDirection="locale"
android:minHeight="?android:listPreferredItemHeight"
android:textDirection="locale" >
···下面的代碼沒有更改透罢,不放在這里
焦點(diǎn)的背景圖顯示
@drawable/local_bg_focus
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true" >
<color android:color="#33000000"/>
</item>
<item android:state_focused="false" >
<color android:color="?android:colorBackground"/>
</item>
</selector>
4.增加onclick事件
在adapter里面監(jiān)聽com.android.settings.localepicker.LocaleDragCell 控件榜晦。
文件目錄:packages/apps/Settings/src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java
如果我們不做任何點(diǎn)擊的其他操作,只需要做點(diǎn)擊切換到最上層的操作羽圃,可以直接寫下面的這個部分的代碼乾胶。
dragCell.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onItemMove(i, 0);
notifyDataSetChanged();
doTheUpdate();
}
});
5.補(bǔ)充說明
文件目錄:packages/apps/Settings/src/com/android/settings/localepicker/LocaleListEditor.java
在這個里面是recyclerview的監(jiān)聽類。
如果還有其他的出來點(diǎn)擊替換其他的點(diǎn)擊事件朽寞,可以通過接口的方式來實(shí)現(xiàn)胚吁。
主要思路:
- 找到recyclerview的item的layout
- 增加焦點(diǎn)的事件
- recyclerview的移動是通過notifyItemMoved(i, 0)來實(shí)現(xiàn)移動的