删除 parent 视图以设置自定义布局视图
remove parent view to set a custom layout view
我正在尝试将自定义布局添加到我的设置应用程序以使用可启动网络的可点击 header 图像进行个性化选项 url 但主要首选项布局已由我的设置设置activiy,我如何删除 parent 视图以便我的自定义布局可以膨胀?
public class DEMENTED extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
private static final String TAG = "DEMENTED";
private static final String KEY_DEMENTED_GITHUB = "https://github.com/cphelps76";
private static final String KEY_DEMENTED_HEADER = "logo";
private static final String KEY_GESTURE_SETTINGS = "prefs_gesture";
Preference mlogo;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.demented_interface, container);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.demented_interface_settings);
mlogo = findPreference(KEY_DEMENTED_HEADER);
Utils.updatePreferenceToSpecificActivityFromMetaDataOrRemove(getActivity(),
getPreferenceScreen(), KEY_GESTURE_SETTINGS);
}
@Override
protected int getMetricsCategory() {
return MetricsLogger.DEMENTED_INTERFACE;
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if (preference == mlogo) {
launchUrl(KEY_DEMENTED_GITHUB);
return true;
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
public boolean onPreferenceChange(Preference preference, Object objValue) {
final String key = preference.getKey();
return true;
}
private void launchUrl(String url) {
Uri uriUrl = Uri.parse(url);
Intent whatever = new Intent(Intent.ACTION_VIEW, uriUrl);
getActivity().startActivity(whatever);
}
}
我通过在 OnCreateView 中膨胀我的 bas 首选项视图并找到 imageview id 然后使我的图像可点击并设置 onclick 侦听器解决了我自己的问题
public class DEMENTED extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener, View.OnClickListener {
private static final String TAG = "DEMENTED";
private static final String KEY_DEMENTED_GITHUB = "https://github.com/cphelps76";
private static final String KEY_GESTURE_SETTINGS = "prefs_gesture";
private static final String KEY_HARDWARE_KEYS = "prefs_buttons";
private ImageView mLogoView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.demented_interface_settings);
removePreferences();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.preference_list_fragment, parent, false);
mLogoView = (ImageView)rootView.findViewById(R.id.logo);
updateView();
return rootView;
}
private boolean hasButtons() {
return getResources().getInteger(
com.android.internal.R.integer.config_deviceHardwareKeys) != 0;
}
private void removePreference(Preference preference) {
getPreferenceScreen().removePreference(preference);
}
private void removePreferences() {
Utils.updatePreferenceToSpecificActivityFromMetaDataOrRemove(getActivity(),
getPreferenceScreen(), KEY_GESTURE_SETTINGS);
if (!hasButtons()) {
removePreference(KEY_HARDWARE_KEYS);
}
}
private void updateView() {
if (mLogoView != null) {
mLogoView.setClickable(true);
mLogoView.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
if (v == mLogoView) {
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
launchUrl(KEY_DEMENTED_GITHUB);
}
}
@Override
protected int getMetricsCategory() {
return MetricsLogger.DEMENTED_INTERFACE;
}
public boolean onPreferenceChange(Preference preference, Object objValue) {
final String key = preference.getKey();
return true;
}
private void launchUrl(String url) {
Uri uriUrl = Uri.parse(url);
Intent demented = new Intent(Intent.ACTION_VIEW, uriUrl);
getActivity().startActivity(demented);
}
}
我正在尝试将自定义布局添加到我的设置应用程序以使用可启动网络的可点击 header 图像进行个性化选项 url 但主要首选项布局已由我的设置设置activiy,我如何删除 parent 视图以便我的自定义布局可以膨胀?
public class DEMENTED extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
private static final String TAG = "DEMENTED";
private static final String KEY_DEMENTED_GITHUB = "https://github.com/cphelps76";
private static final String KEY_DEMENTED_HEADER = "logo";
private static final String KEY_GESTURE_SETTINGS = "prefs_gesture";
Preference mlogo;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.demented_interface, container);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.demented_interface_settings);
mlogo = findPreference(KEY_DEMENTED_HEADER);
Utils.updatePreferenceToSpecificActivityFromMetaDataOrRemove(getActivity(),
getPreferenceScreen(), KEY_GESTURE_SETTINGS);
}
@Override
protected int getMetricsCategory() {
return MetricsLogger.DEMENTED_INTERFACE;
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if (preference == mlogo) {
launchUrl(KEY_DEMENTED_GITHUB);
return true;
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
public boolean onPreferenceChange(Preference preference, Object objValue) {
final String key = preference.getKey();
return true;
}
private void launchUrl(String url) {
Uri uriUrl = Uri.parse(url);
Intent whatever = new Intent(Intent.ACTION_VIEW, uriUrl);
getActivity().startActivity(whatever);
}
}
我通过在 OnCreateView 中膨胀我的 bas 首选项视图并找到 imageview id 然后使我的图像可点击并设置 onclick 侦听器解决了我自己的问题
public class DEMENTED extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener, View.OnClickListener {
private static final String TAG = "DEMENTED";
private static final String KEY_DEMENTED_GITHUB = "https://github.com/cphelps76";
private static final String KEY_GESTURE_SETTINGS = "prefs_gesture";
private static final String KEY_HARDWARE_KEYS = "prefs_buttons";
private ImageView mLogoView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.demented_interface_settings);
removePreferences();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.preference_list_fragment, parent, false);
mLogoView = (ImageView)rootView.findViewById(R.id.logo);
updateView();
return rootView;
}
private boolean hasButtons() {
return getResources().getInteger(
com.android.internal.R.integer.config_deviceHardwareKeys) != 0;
}
private void removePreference(Preference preference) {
getPreferenceScreen().removePreference(preference);
}
private void removePreferences() {
Utils.updatePreferenceToSpecificActivityFromMetaDataOrRemove(getActivity(),
getPreferenceScreen(), KEY_GESTURE_SETTINGS);
if (!hasButtons()) {
removePreference(KEY_HARDWARE_KEYS);
}
}
private void updateView() {
if (mLogoView != null) {
mLogoView.setClickable(true);
mLogoView.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
if (v == mLogoView) {
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
launchUrl(KEY_DEMENTED_GITHUB);
}
}
@Override
protected int getMetricsCategory() {
return MetricsLogger.DEMENTED_INTERFACE;
}
public boolean onPreferenceChange(Preference preference, Object objValue) {
final String key = preference.getKey();
return true;
}
private void launchUrl(String url) {
Uri uriUrl = Uri.parse(url);
Intent demented = new Intent(Intent.ACTION_VIEW, uriUrl);
getActivity().startActivity(demented);
}
}