public class ExampleFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.example_fragment, container, false);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="horizontal" >
<EditText android:id="@+id/edit_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage" />
</LinearLayout>
public class FragmentLayoutTest extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/fragment_intro"
/>
<fragment android:name="com.skw.fragmentlayouttest.ExampleFragment"
android:id="@+id/frag_example"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/fragment_intro"
/>
<FrameLayout
android:id="@+id/frag_example"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
public class FragmentLayoutTest extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 获取FragmentManager
FragmentManager fragmentManager = getFragmentManager();
// 获取FragmentTransaction
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
// 获取ExampleFragment
ExampleFragment fragment = new ExampleFragment();
// 将fragment添加到容器frag_example中
fragmentTransaction.add(R.id.frag_example, fragment);
fragmentTransaction.commit();
}
}
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="PreferenceCategory A">
<!--
(01) android:key是Preferece的id
(02) android:title是Preferece的大标题
(03) android:summary是Preferece的小标题
-->
<CheckBoxPreference
android:key="checkbox_preference"
android:title="title_checkbox_preference"
android:summary="summary_checkbox_preference" />
</PreferenceCategory>
<PreferenceCategory
android:title="PreferenceCategory B">
<!--
android:dialogTitle是对话框的标题
android:defaultValue是默认值
-->
<EditTextPreference
android:key="edittext_preference"
android:title="title_edittext_preference"
android:summary="null"
android:dialogTitle="dialog_title_edittext_preference"
android:defaultValue="null" />
<!--
android:entries是列表中各项的说明
android:entryValues是列表中各项的值
-->
<ListPreference
android:key="list_preference"
android:dialogTitle="Choose font"
android:entries="@array/pref_font_types"
android:entryValues="@array/pref_font_types_values"
android:summary="sans"
android:title="Font"
android:defaultValue="sans"/>
</PreferenceCategory>
<PreferenceCategory
android:title="PreferenceCategory C">
<SwitchPreference
android:key="switch_preferece"
android:title="title_switch_preferece"
android:defaultValue="true" />
<SeekBarPreference
android:key="seekbar_preference"
android:title="title_seekbar_preference"
android:max="100"
android:defaultValue="30" />
</PreferenceCategory>
</PreferenceScreen>
public class PrefsFragment extends PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener, Preference.OnPreferenceClickListener {
private static final String TAG = "##PrefsFragment##";
private static final String CHECK_PREFERENCE = "checkbox_preference";
private static final String EDITTEXT_PREFERENCE = "edittext_preference";
private static final String LIST_PREFERENCE = "list_preference";
private static final String SWITCH_PREFERENCE = "switch_preferece";
private static final String SEEKBAR_PREFERENCE = "seekbar_preference";
private Preference mEditText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
mEditText = (Preference) findPreference(EDITTEXT_PREFERENCE);
mEditText.setOnPreferenceClickListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
// Set summary to be the user-description for the selected value
Preference connectionPref = findPreference(key);
if (key.equals(CHECK_PREFERENCE)) {
boolean checked = sharedPreferences.getBoolean(key, false);
Log.d(TAG, "CheckBox: checked="+checked);
} else if (key.equals(EDITTEXT_PREFERENCE)) {
String value = sharedPreferences.getString(key, "");
connectionPref.setSummary(value);
Log.d(TAG, "EditText: value="+value);
} else if (key.equals(LIST_PREFERENCE)) {
String value = sharedPreferences.getString(key, "");
connectionPref.setSummary(value);
Log.d(TAG, "List: value="+value);
} else if (key.equals(SWITCH_PREFERENCE)) {
boolean checked = sharedPreferences.getBoolean(key, false);
Log.d(TAG, "Switch: checked="+checked);
} else if (key.equals(SEEKBAR_PREFERENCE)) {
int value = sharedPreferences.getInt(key, 0);
Log.d(TAG, "Seekbar: value="+value);
}
}
@Override
public boolean onPreferenceClick(Preference preference) {
SharedPreferences sharedPreferences = preference.getSharedPreferences();
String value = sharedPreferences.getString(preference.getKey(), "");
Log.d(TAG, "onPreferenceClick: value="+value);
return true;
}
@Override
public void onResume() {
super.onResume();
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
super.onPause();
}
}
public class FragmentTest extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
getFragmentManager().beginTransaction().replace(android.R.id.content,
new PrefsFragment()).commit();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有