本文整理了Java中android.support.v4.app.Fragment.onInflate()
方法的一些代码示例,展示了Fragment.onInflate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Fragment.onInflate()
方法的具体详情如下:
包路径:android.support.v4.app.Fragment
类名称:Fragment
方法名:onInflate
[英]Called when a fragment is being created as part of a view layout inflation, typically from setting the content view of an activity. This may be called immediately after the fragment is created from a tag in a layout file. Note this is before the fragment's #onAttach(Activity) has been called; all you should do here is parse the attributes and save them away.
This is called every time the fragment is inflated, even if it is being inflated into a new instance with saved state. It typically makes sense to re-parse the parameters each time, to allow them to change with different configurations.
Here is a typical implementation of a fragment that can take parameters both through attributes supplied here as well from #getArguments():
development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
Note that parsing the XML attributes uses a "styleable" resource. The declaration for the styleable used here is:
development/samples/ApiDemos/res/values/attrs.xml fragment_arguments
The fragment can then be declared within its activity's content layout through a tag like this:
development/samples/ApiDemos/res/layout/fragment_arguments.xml from_attributes
This fragment can also be created dynamically from arguments given at runtime in the arguments Bundle; here is an example of doing so at creation of the containing activity:
development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
[中]当片段作为视图布局的一部分创建时调用,通常通过设置活动的内容视图来调用。这可以在从布局文件中的标记创建片段后立即调用。注意,这是在调用片段的#onAttach(活动)之前;这里您所要做的就是解析属性并保存它们。
每次膨胀片段时都会调用此函数,即使它正在膨胀为具有保存状态的新实例。每次重新解析参数通常是有意义的,以允许它们随不同的配置进行更改。
下面是一个片段的典型实现,它可以通过此处提供的属性以及从#getArguments()获取参数:
development/samples/ApiDemos/src/com/example/android/api/app/FragmentArguments。JAVA
请注意,解析XML属性使用“可样式化”资源。此处使用的styleable的声明是:
开发/样本/ApiDemos/res/values/attrs。xml片段参数
然后可以通过如下标记在其活动的内容布局中声明片段:
开发/samples/ApiDemos/res/layout/fragment\u参数。来自属性的xml
这个片段也可以从arguments包中运行时给出的参数动态创建;以下是创建包含活动时执行此操作的示例:
development/samples/ApiDemos/src/com/example/android/api/app/FragmentArguments。JAVA
代码示例来源:origin: com.uphyca/android-junit4-robolectric
/**
* @param activity
* @param attrs
* @param savedInstanceState
* @see android.support.v4.app.Fragment#onInflate(android.app.Activity, android.util.AttributeSet, android.os.Bundle)
*/
public void onInflate(Activity activity,
AttributeSet attrs,
Bundle savedInstanceState) {
mFragment.onInflate(activity, attrs, savedInstanceState);
}
代码示例来源:origin: shazam/android-aspects
@Override
public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
super.onInflate(activity, attrs, savedInstanceState);
dispatcher.dispatchOnInflate(this, activity, attrs, savedInstanceState);
}
代码示例来源:origin: fr.avianey/facebook-android-api
@Override
public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
super.onInflate(activity, attrs, savedInstanceState);
TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.com_facebook_picker_fragment);
setShowPictures(a.getBoolean(R.styleable.com_facebook_picker_fragment_show_pictures, showPictures));
String extraFieldsString = a.getString(R.styleable.com_facebook_picker_fragment_extra_fields);
if (extraFieldsString != null) {
String[] strings = extraFieldsString.split(",");
setExtraFields(Arrays.asList(strings));
}
showTitleBar = a.getBoolean(R.styleable.com_facebook_picker_fragment_show_title_bar, showTitleBar);
titleText = a.getString(R.styleable.com_facebook_picker_fragment_title_text);
doneButtonText = a.getString(R.styleable.com_facebook_picker_fragment_done_button_text);
titleBarBackground = a.getDrawable(R.styleable.com_facebook_picker_fragment_title_bar_background);
doneButtonBackground = a.getDrawable(R.styleable.com_facebook_picker_fragment_done_button_background);
a.recycle();
}
代码示例来源:origin: stackoverflow.com
fragment.mInLayout = true;
fragment.mFragmentManager = mFragments;
fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
mFragments.addFragment(fragment, true);
fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
代码示例来源:origin: com.google.android/support-v4
fragment.mInLayout = true;
fragment.mFragmentManager = mFragments;
fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
mFragments.addFragment(fragment, true);
fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
代码示例来源:origin: kingargyle/adt-leanback-support
fragment.mInLayout = true;
fragment.mFragmentManager = this;
fragment.onInflate(mActivity, attrs, fragment.mSavedFragmentState);
addFragment(fragment, true);
fragment.onInflate(mActivity, attrs, fragment.mSavedFragmentState);
内容来源于网络,如有侵权,请联系作者删除!