由於Setting整個theme被修改為暗色系關係
彈出視窗卻沒有全部被修改到
如下圖 所以需要尋找原因並改正
閒言閒語:
目前看到的
大約兩種彈出視窗
1. AlertDialog
2. ListPreference
AlertDialog
|
ListPreference
|
1. AlertDialog
(1). new AlertDialog.Builder(mContext,2) <---觀察AlertDialog得知多載的第二個值是style更改
(2). new AlertDialog.Builder(new ContextThemeWrapper(mContext, R.style.AlertDialogCustom)) <---傳入custom style //reference: http://blog.csdn.net/mybeta/article/details/44660453
(3). 用ContextThemeWrapper修改了原context的style也無法該更改AlertDialog.setSingleChoiceItems的樣式,必須自行custom
寫一個custom_checkedtextview格式 (ryan_custom_checkedtextview)
用一個ArrayAdapter放入setSingleChoiceItems (DreamSettings)
這部份感覺像是AOSP不太完善的地方 就細部不會吃到style?
範例:
LINUX/android/packages/apps/Settings/src/com/android/settings/DreamSettings.java
final CharSequence[] items = {
mContext.getString(R.string.screensaver_settings_summary_dock),
mContext.getString(R.string.screensaver_settings_summary_sleep),
mContext.getString(R.string.screensaver_settings_summary_either_short)
};
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getActivity(), R.layout.ryan_custom_checkedtextview, items);
return new AlertDialog.Builder(mContext)
.setTitle(R.string.screensaver_settings_when_to_dream)
//.setSingleChoiceItems(items, initialSelection, new DialogInterface.OnClickListener() {
.setSingleChoiceItems(adapter, initialSelection, new DialogInterface.OnClickListener() {
LINUX/android/packages/apps/Settings/res/layout/ryan_custom_checkedtextview.xml :
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:drawableLeft="?android:attr/listChoiceIndicatorSingle"
android:paddingLeft="10dip"
android:textColor="#FFFFFF"
android:gravity="center_vertical"
android:ellipsize="marquee" />
2. ListPreference
DevelopmentSettings部份將hdcpChecking重新指定到符合custom的List樣式 (development_prefs & WarnedListPreference)
然後因為修改後原生的click事件失效 (可再多研究原因)
所以修改 Preference 的 ClickListener事件 (DevelopmentSettings)
範例:
LINUX/android/packages/apps/Settings/res/xml/development_prefs.xml:
這份文件是開發者模式{} 裏面的表單
將想修改的原ListPreference改com.android.settings.WarnedListPreference
<com.android.settings.WarnedListPreference
android:dialogTitle="@string/hdcp_checking_dialog_title"
android:key="hdcp_checking"
android:title="@string/hdcp_checking_title"
android:entries="@array/hdcp_checking_titles"
android:entryValues="@array/hdcp_checking_values"
android:summary="@string/screen_timeout_summary"
android:persistent="false"/>
LINUX/android/packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java:
+
+import android.preference.Preference.OnPreferenceClickListener;
+
public class DevelopmentSettings extends SettingsPreferenceFragment
implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
- OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable {
+ OnPreferenceChangeListener, OnPreferenceClickListener, SwitchBar.OnSwitchChangeListener, Indexable {
+
+ private WarnedListPreference hdcpChecking;
+
public void onCreate(Bundle icicle) {
- Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY);
+ hdcpChecking = (WarnedListPreference)findPreference(HDCP_CHECKING_KEY);
if (hdcpChecking != null) {
+Log.i(TAG, "in if (hdcpChecking != null) {");
+
+ hdcpChecking.setOnPreferenceClickListener(this);
+
mAllPrefs.add(hdcpChecking);
removePreferenceForProduction(hdcpChecking);
+
private void updateHdcpValues() {
- ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
+ //ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
+ hdcpChecking = (WarnedListPreference) findPreference(HDCP_CHECKING_KEY);
+
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
+ //if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
+ if (preference==hdcpChecking) {
+Log.i(TAG, "in if (preference==hdcpChecking) {");
SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString());
+Log.i(TAG, "in newValue.toString()"+newValue.toString());
updateHdcpValues();
pokeSystemProperties();
return true;
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ if (preference == hdcpChecking) {
+ hdcpChecking.click();
+ }
+
+ return false;
+ }
+
---------------下面兩個沿用之前的更動,為了方便愈度還是貼了出來----------------
WarnedListPreference:
package com.android.settings;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.preference.ListPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.android.settings.R;
import android.util.Log;
public class WarnedListPreference extends ListPreference implements OnItemClickListener {
private static final String TAG = "WarnedListPreference";
private int mClickedDialogEntryIndex;
private CharSequence mDialogTitle;
public WarnedListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onClick() {
// Ignore this until an explicit call to click()
}
public void click() {
super.onClick();
}
@Override
protected View onCreateDialogView() {
Log.i(TAG, "in protected View onCreateDialogView() {");
// TODO Auto-generated method stub
// inflate custom layout with custom title & listview
View view = View.inflate(getContext(), R.layout.preference_warnedlist, null);
mDialogTitle = getDialogTitle();
if(mDialogTitle == null) mDialogTitle = getTitle();
((TextView) view.findViewById(R.id.dialog_title)).setText(mDialogTitle);
ListView list = (ListView) view.findViewById(android.R.id.list);
// note the layout we're providing for the ListView entries
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
getContext(), R.layout.btn_radio,
getEntries());
list.setAdapter(adapter);
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
list.setItemChecked(findIndexOfValue(getValue()), true);
list.setOnItemClickListener(this);
//ist.setOnItemClickListener(this);
return view;
}
@Override
protected void onPrepareDialogBuilder(Builder builder) {
Log.i(TAG, "in protected void onPrepareDialogBuilder(Builder builder) {");
// adapted from ListPreference
if (getEntries() == null || getEntryValues() == null) {
// throws exception
super.onPrepareDialogBuilder(builder);
return;
}
mClickedDialogEntryIndex = findIndexOfValue(getValue());
// .setTitle(null) to prevent default (blue)
// title+divider from showing up
builder.setTitle(null);
builder.setPositiveButton(null, null);
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Log.i(TAG, "in public void onItemClick(AdapterView<?> parent, View view, int position,");
// TODO Auto-generated method stub
mClickedDialogEntryIndex = position;
WarnedListPreference.this.onClick(getDialog(), DialogInterface.BUTTON_POSITIVE);
getDialog().dismiss();
}
@Override
protected void onDialogClosed(boolean positiveResult) {
Log.i(TAG, "in protected void onDialogClosed(boolean positiveResult) {");
// TODO Auto-generated method stub
super.onDialogClosed(positiveResult);
if (positiveResult && mClickedDialogEntryIndex >= 0
&& getEntryValues() != null) {
String value = getEntryValues()[mClickedDialogEntryIndex]
.toString();
if (callChangeListener(value)) {
setValue(value);
}
}
}
}
preference_warnedlist.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/dialog_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:textColor="@color/reborn12"
android:textSize="22sp" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
android:divider="@color/reborn01" />
</LinearLayout>
筆記完畢
0 意見:
張貼留言