I am trying to figure out why the layout of my Preference menu is displayed in a false way on 10' tablets when using it in landscape mode. It looks like the lines that are to the right of the Checkboxes are actually to the left of them. You can see this here http://imageshack.us/photo/my-images/109/schnappschuss2013052109.png/
On 7' tablets, everything works like expected to do.
My menu looks like that:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory
android:title="#string/pref_message"
android:key="pref_key_message_settings">
<CheckBoxPreference
android:key="pref_key_add_timestamp"
android:summary="#string/pref_summary_addTimestamp"
android:title="#string/pref_addTimestamp"
android:defaultValue="true"/>
<ListPreference
android:dependency="pref_key_add_timestamp"
android:summary="#string/pref_summary_timestamp_option"
android:key="pref_key_timestamp_option"
android:title="#string/pref_timestampOption"
android:dialogTitle="#string/pref_timestampOptionDialog"
android:entries="#array/pref_timestampArray"
android:entryValues="#array/pref_timestampValues"
android:defaultValue="Time" />
<CheckBoxPreference
android:key="pref_key_add_newline"
android:summary="#string/pref_summary_addNewLine"
android:title="#string/pref_addNewLine"
android:defaultValue="true"/>
<ListPreference
android:dependency="pref_key_add_newline"
android:key="pref_key_newline_option"
android:summary="#string/pref_summary_newline_option"
android:title="#string/pref_newLineOption"
android:dialogTitle="#string/pref_newLineOptionDialog"
android:entries="#array/pref_newLineArray"
android:entryValues="#array/pref_newLineValues"
android:defaultValue="LF" />
<CheckBoxPreference
android:key="pref_key_clear_text"
android:summary="#string/pref_summary_clearText"
android:title="#string/pref_clearText"
android:defaultValue="false"/>
</PreferenceCategory>
<PreferenceCategory
android:title="#string/pref_storage"
android:key="pref_key_storage_settings">
<EditTextPreference
android:key="pref_key_change_name"
android:summary="#string/pref_summary_editFilename"
android:title="#string/pref_editFilename"
android:defaultValue="history"/>
<CheckBoxPreference
android:key="pref_key_add_date"
android:summary="#string/pref_summary_addDate"
android:title="#string/pref_addDate"
android:defaultValue="true"/>
<CheckBoxPreference
android:key="pref_key_add_time"
android:summary="#string/pref_summary_addTime"
android:title="#string/pref_addTime"
android:defaultValue="true"/>
<at.rtcmanager.ConfirmPreference
android:key="pref_key_clear_history"
android:summary="#string/pref_summary_clearHistory"
android:title="#string/pref_clearHistory"/>
</PreferenceCategory>
<PreferenceCategory
android:title="#string/pref_time"
android:key="pref_key_time_settings">
<CheckBoxPreference
android:key="pref_key_autosend_time"
android:summary="#string/pref_summary_austosendTime"
android:title="#string/pref_autosendTime"
android:defaultValue="false"/>
<ListPreference
android:key="pref_key_mode_sentTime"
android:title="#string/pref_mode_sentTime"
android:summary="#string/pref_summary_mode_sentTime"
android:dialogTitle="#string/pref_modeSentTimeDialog"
android:entries="#array/pref_sentTimeModeArray"
android:entryValues="#array/pref_sentTimeValues"
android:defaultValue="10Byte" />
</PreferenceCategory>
<PreferenceCategory
android:title="#string/pref_about"
android:key="pref_key_settings_about">
<Preference android:title="#string/prefs_about_app" >
<intent android:action="AboutActivity"/>
</Preference>
</PreferenceCategory>
</PreferenceScreen>
and is loded with:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsMenuFragment())
.commit();
}
public static class SettingsMenuFragment extends PreferenceFragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.app_prefs);
}
}
I had the same problem. My solution is to extend SettingsActivity from usual Activity, not from PreferenceActivity. But SettingsFragment should extend PreferenceFragment of course. It helped me, hope this solves your issue too.
Related
I want to increase size of preference categaory title programmatically so how can do this ?
below is my xml
<PreferenceCategory android:title="#string/languagetitle"
android:key="LanguageCategory">
<ListPreference
android:defaultValue="#string/defaultlanguagevalue"
android:entries="#array/language"
android:entryValues="#array/languagevalues"
android:key="language"
android:summary="#string/languageSubtitle"
android:title="English" /></PreferenceCategory>
<PreferenceCategory android:title="#string/Notificationtitle"
android:key="NotificationCategory">
<SwitchPreference
android:defaultValue="true"
android:key="notification"
android:summary="#string/NotificationSubtitle"
android:title="#string/Notificationcontent" />
<ListPreference
android:entries="#array/time"
android:entryValues="#array/time"
android:key="time"
android:summary="#string/NotificationSubtitleTime"
android:title="#string/NotificationcontentTime"
android:defaultValue="9am"
/>
</PreferenceCategory>
<PreferenceCategory
android:title="#string/FontTitle"
android:key="FontStyleCategory"
>
<faisal.home.com.tafaqquhfiddin.FontStylePreference
android:key="fontstyle"
/>
<faisal.home.com.tafaqquhfiddin.FontSizePreference
android:key="fontsize"
/>
</PreferenceCategory>
<PreferenceCategory
android:title="#string/OTHERS"
android:key="FontSizeCategory">
<faisal.home.com.tafaqquhfiddin.About_us_Preference/>
</PreferenceCategory>
</PreferenceScreen>
and below is my code where i want to increase its size programmatically
public void OnLanguageChange()
{
SharedPreferences sharedPreferences= PreferenceManager.getDefaultSharedPreferences(getActivity());
PreferenceCategory languageCategory =(PreferenceCategory) findPreference("LanguageCategory");
Preference language =findPreference(MyAppManager.LANGUAGE_KEY);
PreferenceCategory notificationCategory =(PreferenceCategory) findPreference("NotificationCategory");
Preference notification =findPreference(MyAppManager.NOTIFICATION_KEY);
Preference notificationTime =findPreference(MyAppManager.NOTIFICATION_TIME_KEY);
PreferenceCategory fontStyleCategory=(PreferenceCategory)findPreference("FontStyleCategory");
PreferenceCategory fontSizeCategory=(PreferenceCategory)findPreference("FontSizeCategory");
languageCategory.setTitle(getString(R.string.languagetitle));
language.setSummary(getString(R.string.languageSubtitle));
notificationCategory.setTitle(getString(R.string.Notificationtitle));
notification.setTitle(getString(R.string.Notificationcontent));
notification.setSummary(getString(R.string.NotificationSubtitle));
notificationTime.setTitle(getString(R.string.NotificationcontentTime));
notificationTime.setSummary(getString(R.string.NotificationSubtitleTime)+" "+ sharedPreferences.getString(MyAppManager.NOTIFICATION_TIME_KEY, "9am"));
fontStyleCategory.setTitle(getString(R.string.FontTitle));
fontSizeCategory.setTitle(getString(R.string.FontSize));
}
I am new to android. Please help me how can i achieve this
I want use PreferenceScreen in my application, and create XML layout for this activity in res/xml/setting_preference.xml. but this XML layout is very simple, i want use this layout in another layout.
For example : i want use setting_preference.xml into setting_activity.xml , setting_activity.xml path is res/layout/setting_activity.xml.
How can i it?
setting_preference XML code:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="setting_title_title_category"
android:title="Title options">
<CheckBoxPreference
android:id="#+id/setting_title_show_id"
android:key="setting_title_show"
android:title="Show Main Title"
android:summary="Show/hide MainPage title"
android:checked="true"/>
<EditTextPreference
android:key="setting_title_text"
android:title="Set Main Title"
android:summary="Change MainPage title"
android:dialogTitle="Change Title"
android:dialogMessage="Change title please..."/>
</PreferenceCategory>
<PreferenceCategory
android:key="setting_title_font_category"
android:title="Font options">
<ListPreference
android:key="setting_title_font_color"
android:title="Title font colors"
android:summary="Change title font colors"
android:entries="#array/colors"
android:entryValues="#array/colors"
android:dialogTitle="Change font color" />
</PreferenceCategory>
<RingtonePreference
android:title="tes"/>
</PreferenceScreen>
setting_activity XML code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.tellfa.nikandroid.mytestdbproject.SettingPage">
</RelativeLayout>
Setting Page code:
public class SettingPage extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
}
#Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals("setting_title_font_color")) {
// get preference by key
Preference pref = findPreference(key);
// do your stuff here
}
if (key.equals("setting_title_show")){
Preference pref = findPreference(key);
}
}
public static class MyPreferenceFragment extends PreferenceFragment {
#Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.setting_prefrences);
}
}
}
Add a frameLayout where you want to load your xml preference file in the layout xml file and implement PreferenceFragment in that activity.
I want to use Snackbar onSharedPreferenceChange() inside my PreferenceFragment hosted by a Activity.
preference.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="ll_main">
<PreferenceCategory android:title="#string/push_notification">
<SwitchPreference android:title="#string/transectional_notification"
android:key="trans_not"
android:defaultValue="true"
android:summary="#string/get_notified_about_any_changes_related_to_your_transections"/>
<SwitchPreference android:title="#string/promotional_notification"
android:key="prom_not"
android:defaultValue="true"
android:summary="#string/get_notified_about_referalls"/>
</PreferenceCategory>
<PreferenceCategory android:title="#string/other_notifications">
<SwitchPreference android:title="#string/email_notifications"
android:defaultValue="true"
android:key="email_not" />
<SwitchPreference android:title="#string/sms_notifications"
android:defaultValue="true"
android:key="sms_not"/>
</PreferenceCategory>
<PreferenceCategory android:title="#string/recommendation_setting">
<com.til.recharger.widgets.PhoneEditTextPreference
android:title="#string/mobile_no"
android:inputType="number"
android:summary="8587035342"
android:key="mob_no_edit"/>
<ListPreference android:title="#string/operator"
android:summary="Airtel"
android:key="operator_list"/>
<ListPreference android:title="#string/circle"
android:summary="New Delhi"
android:key="circle_list"/>
<ListPreference
android:title="Plan type"
android:entries="#array/listentries"
android:entryValues="#array/listentries"
android:summary="Postpaid"
android:defaultValue="Prepaid"
android:key="plan_key"/>
</PreferenceCategory>
<PreferenceCategory android:title="#string/plan_info">
<com.til.recharger.widgets.NumberPickerPreference
android:title="#string/bill_cycle"
android:summary="2"
android:persistent="true"
android:key="bill_cycle_edit"/>
<com.til.recharger.widgets.CustomEditTextPreference
android:title="#string/monthly_data_limit"
android:summary="%s"
android:inputType="number"
android:key="monthly_limit_edit"/>
<ListPreference
android:title="#string/preffered_network_type"
android:entries="#array/mobiledataoptions"
android:entryValues="#array/mobiledatavalues"
android:summary="3G"
android:defaultValue="3G"
android:key="pref_data_list"/>
</PreferenceCategory>
</PreferenceScreen>
My function for showing snackbar is :
public void hideKeyWithError(final String error) {
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
AppUtils.hide_keyboard(getActivity());
Snackbar.make(view,error,Snackbar.LENGTH_LONG).show();
}
}, (300));
}
I don't know what to pass as 'view' to snackbar to show it.
PS : I tried passing PreferenceScreen to Snackbar, But didn't work out. Thanks in Advance.
Try this for get view
View view = getView();
So the code is.
public void hideKeyWithError(final String error) {
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
View view = getView();
AppUtils.hide_keyboard(getActivity());
Snackbar.make(view,error,Snackbar.LENGTH_LONG).show();
}
}, (300));
}
View param of Snackbar.make() means a view on which Snackbar can find parent to display Snackbar on the top of screen
Snackbar will try and find a parent view to hold Snackbar's view from the value given to view
Link
by default android PreferenceActivity layouts are left to right and i can not change PreferenceActivity widgets to right from left. for example see this screen shot please:
i want to change this layout like with below screen shot
PreferenceActivity Activity:
public class ActivitySettings extends PreferenceActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.app_settings);
}
}
PreferenceActivity layout:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:icon="#drawable/img_app_setting" >
<PreferenceCategory android:title="#string/settings_alarm_title" >
<CheckBoxPreference
android:key="PLAY_SOUND"
android:summaryOff="#string/settings_summary_off_play_sound"
android:summaryOn="#string/settings_summary_on_play_sound"
android:title="#string/settings_play_sound" />
<CheckBoxPreference
android:key="SHOW_NOTIFICATION"
android:summaryOff="#string/settings_summary_off_show_notification"
android:summaryOn="#string/settings_summary_on_show_notification"
android:title="#string/settings_show_notification" />
</PreferenceCategory>
</PreferenceScreen>
I have MenuSettings in which I have PreferenceActivity class. In PreferenceActivity I have displayed checkboxPreference like below.
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory
android:title="Options">
<CheckBoxPreference
android:key="pref_opt1"
android:title="Option 1"
android:summary="Tick to set this option"
android:defaultValue="true"
/>
<CheckBoxPreference
android:key="pref_opt2"
android:title="Option 2"
android:summary="Tick to set this option"
android:defaultValue="true"
/>
</PreferenceCategory>
</PreferenceScreen>
I want to use checkboxes to perform function for synchronization that I have build, But Please can any body let me know how to use checkboxes in PreferenceActivity. Is there any need to create another Activity? or we can perform function in same PreferenceActivity?
here is my PreferenceActivity:
public class SharedPref extends PreferenceActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.sharedpref);
}
// StorePreference method{
}
// readPreferences method{
}
}