Java源码示例:android.view.LayoutInflater
示例1
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View myView = inflater.inflate(R.layout.constraintlayout_fragment, container, false);
//set it up so all the button work in this fragment.
(myView.findViewById(R.id.button01)).setOnClickListener(this);
(myView.findViewById(R.id.button02)).setOnClickListener(this);
(myView.findViewById(R.id.button03)).setOnClickListener(this);
(myView.findViewById(R.id.button04)).setOnClickListener(this);
(myView.findViewById(R.id.button05)).setOnClickListener(this);
(myView.findViewById(R.id.button06)).setOnClickListener(this);
(myView.findViewById(R.id.button07)).setOnClickListener(this);
(myView.findViewById(R.id.button08)).setOnClickListener(this);
(myView.findViewById(R.id.button09)).setOnClickListener(this);
(myView.findViewById(R.id.button10)).setOnClickListener(this);
(myView.findViewById(R.id.button11)).setOnClickListener(this);
//output to the screen.
output = myView.findViewById(R.id.output);
return myView;
}
示例2
private static ImageButton createButton(
@NonNull final Context context,
@NonNull final ViewGroup root,
@DrawableRes final int image,
@NonNull final OnClickListener clickListener) {
final ImageButton ib = (ImageButton)LayoutInflater.from(context).inflate(R.layout.flat_image_button, root, false);
final int buttonPadding = General.dpToPixels(context, 14);
ib.setPadding(buttonPadding, buttonPadding, buttonPadding, buttonPadding);
ib.setImageResource(image);
ib.setOnClickListener(clickListener);
return ib;
}
示例3
@Override
protected View createView(LayoutInflater layoutInflater, ViewGroup viewGroup) {
// 不显示默认标题
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
mCommonFrameLayout = new CommonFrameLayout(getContext());
mToolbar = mCommonFrameLayout.getTitleView();
mMoreButton = mToolbar.addMoreImageButton();
LinearLayout content = LayoutUtil.newCommonLayout(getContext());
mListView = new ListView(getContext());
mListView.setCacheColorHint(0x00000000);
mListView.setDividerHeight(0);
mListView.setLayoutParams(LayoutUtil.newMatchFrameLayoutParams());
content.addView(mListView);
mCommonFrameLayout.setContent(content);
return mCommonFrameLayout;
}
示例4
@SuppressLint("NewApi")
public TextRoundCornerProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
if (!isInEditMode()) {
isProgressBarCreated = false;
isProgressSetBeforeDraw = false;
isMaxProgressSetBeforeDraw = false;
isBackgroundColorSetBeforeDraw = false;
isProgressColorSetBeforeDraw = false;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.round_corner_progress_bar_round_corner_with_text_layout, this);
setup(context, attrs);
isProgressBarCreated = true;
} else {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
setBackground(new ColorDrawable(Color.parseColor("#CCCCCC")));
} else {
setBackgroundColor(Color.parseColor("#CCCCCC"));
}
setGravity(Gravity.CENTER);
setPadding(0, (int)dp2px(5), 0, (int)dp2px(5));
TextView tv = new TextView(context);
tv.setText("TextRoundCornerProgressBar");
addView(tv);
}
}
示例5
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.folder_item, null);
// service info
File file = getItem(position);
// name
TextView name = (TextView) view.findViewById(R.id.name);
if (file == null) {
name.setText("[ .. ]");
} else {
name.setText(file.getName());
}
return (view);
}
示例6
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = null;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.rowlayout, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
textView.setText(values[position]);
// Change the icon for Windows and iPhone
String s = values[position];
if (s.startsWith("iPhone")) {
imageView.setImageResource(R.drawable.no);
} else {
imageView.setImageResource(R.drawable.ok);
}
return rowView;
}
示例7
@Override
protected View createView(LayoutInflater layoutInflater, ViewGroup viewGroup) {
// 不显示默认标题
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
mCommonFrameLayout = new CommonFrameLayout(getContext());
mToolbar = mCommonFrameLayout.getTitleView();
mAutoPlayType = ViewUtil.newSpinnerItemView(getContext(),
"播放方式", "",
PlayUtil.getPlayTypeName(Constant.PlayType.TDEFAULT),
PlayUtil.getPlayTypeName(Constant.PlayType.TIMING));
mAutoPlaySleepTime = new EditTextItemView(getContext());
mAutoPlaySleepTime.setName("播放休眠时间");
mAutoPlaySleepTime.setExtendHint("未设置");
mAutoPlaySleepTime.setUnit("秒");
mAutoPlaySleepTime.setInputType(com.sky.xposed.common.Constant.InputType.NUMBER_SIGNED);
mCommonFrameLayout.addContent(mAutoPlayType);
mCommonFrameLayout.addContent(mAutoPlaySleepTime);
return mCommonFrameLayout;
}
示例8
public void notifyUserForNethunter(){
final ViewGroup nullParent = null;
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
View view = layoutInflater.inflate(R.layout.notify1, nullParent);
TextView textView = view.findViewById(R.id.textView);
alertDialog.setView(view);
alertDialog.setCancelable(false);
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("IsNethunterNotified", true);
editor.apply();
isNethunterNotified = sharedPreferences.getBoolean("IsNethunterNotified", false);
dialog.dismiss();
}
});
alertDialog.show();
textView.setText(R.string.nethunter_warning_content);
}
示例9
/**
* 初始化方法,获取属性等操作
*/
private void init(Context context, AttributeSet attrs) {
LayoutInflater.from(context).inflate(R.layout.vm_widget_edit, this);
mInputView = findViewById(R.id.vm_edit_input_view);
mClearIcon = findViewById(R.id.vm_edit_clear_icon);
mEyeIcon = findViewById(R.id.vm_edit_eye_icon);
// 定义默认值
mTextColor = VMColor.byRes(R.color.vm_black_87);
mTextSize = (int) VMDimen.sp2px(14);
mHint = "";
mLimit = "";
mMode = Mode.TEXT;
mEnableClear = true;
mEnableEye = false;
mClearRes = R.drawable.vm_ic_close;
mEyeRes = R.drawable.vm_ic_eye_off;
// 获取控件的属性值
handleAttrs(context, attrs);
initEditView();
}
示例10
public RecipientAlternatesAdapter(final Context context,final Cursor c,final long currentId,final int queryMode,final OnCheckedItemChangedListener listener)
{
super(context,c,0);
mLayoutInflater=LayoutInflater.from(context);
mCurrentId=currentId;
mCheckedItemChangedListener=listener;
if(queryMode==QUERY_TYPE_EMAIL)
mQuery=Queries.EMAIL;
else if(queryMode==QUERY_TYPE_PHONE)
mQuery=Queries.PHONE;
else
{
mQuery=Queries.EMAIL;
Log.e(TAG,"Unsupported query type: "+queryMode);
}
}
示例11
@Override
public View getView(int index, View view, ViewGroup viewGroup) {
View layout;
if (view instanceof LinearLayout) {
layout = view;
} else {
LayoutInflater factory = LayoutInflater.from(context);
layout = factory.inflate(R.layout.bookmark_picker_list_item, viewGroup, false);
}
if (!cursor.isClosed()) {
cursor.moveToPosition(index);
CharSequence title = cursor.getString(BookmarkPickerActivity.TITLE_COLUMN);
((TextView) layout.findViewById(R.id.bookmark_title)).setText(title);
CharSequence url = cursor.getString(BookmarkPickerActivity.URL_COLUMN);
((TextView) layout.findViewById(R.id.bookmark_url)).setText(url);
} // Otherwise... just don't update as the object is shutting down
return layout;
}
示例12
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
switch (viewType) {
case VIEW_TYPE_GENERAL_SETTINGS:
return new GeneralSettingsViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.view_general_settings, parent, false));
case VIEW_TYPE_AD_SERVER_SETTINGS:
return new AdServerSettingsViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.view_ad_server_settings, parent, false));
case VIEW_TYPE_PREBID_SERVER_SETTINGS:
return new PrebidServerSettingsViewholder(LayoutInflater.from(parent.getContext()).inflate(R.layout.view_prebid_server_settings, parent, false));
case VIEW_TYPE_SUBMIT:
return new SubmitViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.view_submit, parent, false));
default:
return new DividerViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.view_divider, parent, false));
}
}
示例13
@Override
public View createNodeView(TreeNode node, PlaceItem value) {
final LayoutInflater inflater = LayoutInflater.from(context);
final View view = inflater.inflate(R.layout.layout_place_node, null, false);
TextView placeName = (TextView) view.findViewById(R.id.place_name);
placeName.setText(value.name);
Random r = new Random();
boolean like = r.nextBoolean();
PrintView likeView = (PrintView) view.findViewById(R.id.like);
likeView.setIconText(context.getString(like ? R.string.ic_thumbs_up : R.string.ic_thumbs_down));
return view;
}
示例14
@Override
protected View inflaterView(LayoutInflater inflater, ViewGroup container,
Bundle bundle) {
View root = View.inflate(outsideAty,
R.layout.frag_pull_refresh_listview, null);
return root;
}
示例15
@Override
final public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
ViewHolder vh;
if (recyclerAdapterHelper.isHeaderType(viewType)) {
vh = onCreateHeaderViewHolder(LayoutInflater.from(parent.getContext()), parent);
vh.setIsRecyclable(false);
} else if (recyclerAdapterHelper.isLoadMoreType(viewType)) {
vh = onCreateLoadMoreViewHolder(LayoutInflater.from(parent.getContext()), parent);
} else if (recyclerAdapterHelper.isFooterType(viewType)) {
vh = onCreateFooterViewHolder(LayoutInflater.from(parent.getContext()), parent);
} else {
vh = onCreateItemViewHolder(LayoutInflater.from(parent.getContext()), parent, viewType);
}
return vh;
}
示例16
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.row, parent, false);
viewHolder = new ViewHolder();
viewHolder.countText = (TextView) convertView.findViewById(R.id.textview);
viewHolder.deleteCheckBox = (CheckBox) convertView.findViewById(R.id.checkBox);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
if (adapterData != null) {
final Item item = adapterData.get(position);
viewHolder.countText.setText(item.getCountString());
if (inDeletionMode) {
viewHolder.deleteCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
countersToDelete.add(item.getId());
}
});
} else {
viewHolder.deleteCheckBox.setOnCheckedChangeListener(null);
}
viewHolder.deleteCheckBox.setChecked(countersToDelete.contains(item.getId()));
viewHolder.deleteCheckBox.setVisibility(inDeletionMode ? View.VISIBLE : View.GONE);
}
return convertView;
}
示例17
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_planet, container, false);
int i = getArguments().getInt(ARG_PLANET_NUMBER);
String planet = getResources().getStringArray(R.array.planets_array)[i];
int imageId = getResources().getIdentifier(planet.toLowerCase(Locale.getDefault()),
"drawable", getActivity().getPackageName());
((ImageView) rootView.findViewById(R.id.image)).setImageResource(imageId);
getActivity().setTitle(planet);
return rootView;
}
示例18
public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
View rootView = inflater.inflate(R.layout.color_select_fragment_layout, null);
LinearLayoutManager llm
= new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
//RECYCER
color_select_recyclerview = (RecyclerView) rootView.findViewById(R.id.color_select_recyclerview);
color_select_recyclerview.setLayoutManager(llm);
data = (ArrayList<String>) getArguments().getSerializable("selectedColor");
adapter = new SelectColorRecyclerAdapter(getActivity(),data);
Log.d(TAG + " data ", data.toString());
color_select_recyclerview.setAdapter(new SelectColorRecyclerAdapter(this.getActivity(), data));
ItemTouchHelper.Callback callback = new MyItemTouchHelperCallback(this);// create MyItemTouchHelperCallback
ItemTouchHelper touchHelper = new ItemTouchHelper(callback); // Create ItemTouchHelper and pass with parameter the MyItemTouchHelperCallback
touchHelper.attachToRecyclerView(color_select_recyclerview); // Attach ItemTouchHelper to RecyclerView
builder.setTitle("Swap Color position");
builder.setView(rootView).setPositiveButton("Ok",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
passData(data);
dialog.dismiss();
}
});
builder.setView(rootView).setNegativeButton("Cancel", null);
return builder.create();
}
示例19
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_collection, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
return view;
}
示例20
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
final LayoutInflater inflater = getActivity().getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
final View view = inflater.inflate(R.layout.fragment_dialogs, null);
builder.setView(view)
.setTitle(R.string.dialog_about_title)
.setPositiveButton(R.string.action_close, (dialog, id) -> {});
if(!BuildConfig.DEBUG) {
builder.setNegativeButton(R.string.check_for_update, (dialog, id) -> listener.onAboutDialogNegativeClick(this));
}
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("America/Denver"));
calendar.setTimeInMillis(BuildConfig.TIMESTAMP);
int year = calendar.get(Calendar.YEAR);
textView = view.findViewById(R.id.dialogMessage);
textView.setText(getString(R.string.dialog_about_message, year));
textView.setMovementMethod(LinkMovementMethod.getInstance());
checkbox = view.findViewById(R.id.checkBoxLayout);
checkbox.setVisibility(View.GONE);
// Create the AlertDialog object and return it
return builder.create();
}
示例21
public FeatureLinearHolder(Context context, ViewGroup linearLayout) {
this.mContext = context;
View v = LayoutInflater.from(context).inflate(R.layout.feature_tab_body,linearLayout,false);
ButterKnife.bind(this,v);
mPlayListFrame.setVisibility(View.GONE);
linearLayout.removeAllViews();
linearLayout.addView(v);
mPlaylistMiniAdapter = new PlaylistMiniAdapter(mPlayListFrame);
mSongMiniAdapter = new SongMiniAdapter(mSongFrame);
}
示例22
/**
* 初始化界面时调用
* @param containerId
* @param contentViewId
*/
public void initContainerViews(int containerId, int contentViewId, int pullToRefreshViewId){
if (!mDisableLoadingView){
mFooterLoadingView = LayoutInflater.from(this).inflate(R.layout.footer_loading_view, null);
mFooterLoadingView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
mContainer = (ViewGroup)findViewById(containerId);
mContentView = (ViewGroup)findViewById(contentViewId);
mPullToRefreshView = (PullToRefreshView)findViewById(pullToRefreshViewId);
if (mPullToRefreshView != null){
mPullToRefreshView.setOnHeaderRefreshListener(this);
mPullToRefreshView.setOnFooterRefreshListener(this);
}
showLoadingView();
}
}
示例23
public DebugView(Context context, AttributeSet attrs) {
super(context, attrs);
// Inflate all of the controls and inject them.
LayoutInflater.from(context).inflate(R.layout.debug_view_content, this);
contextualTitleView = findById(this, R.id.debug_contextual_title);
contextualListView = findById(this, R.id.debug_contextual_list);
enableLayoutTransitions(contextualListView);
((ImageView) findById(this, R.id.debug_icon)).setImageResource(context.getApplicationInfo().icon);
}
示例24
public OrgUnitRow(FragmentManager fm, LayoutInflater layoutInflater, FlowableProcessor<RowAction> processor,
boolean isBgTransparent) {
this.inflater = layoutInflater;
this.processor = processor;
this.isBgTransparent = isBgTransparent;
this.fm = fm;
this.renderType = null;
this.isSearchMode = true;
this.currentSelection = null;
}
示例25
private void initialize() {
mContext = getContext();
mInflater = LayoutInflater.from(mContext);
mCenter = NotificationDelegater.getInstance().center();
mCenter.addListener(this);
mGestureDetector = new GestureDetectorCompat(mContext, this);
mH = new H(this);
mContentView = new ContentView(mContext);
addView(mContentView,
new FrameLayout.LayoutParams(
mContentView.mWidth, mContentView.mHeight,
Gravity.CENTER | Gravity.TOP));
}
示例26
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_sls_preference,
container, false);
viewModel = new SlsPreferenceViewModel(getContext(), preferenceStore, playerController);
binding.setViewModel(viewModel);
binding.readmeMessage.setMovementMethod(new LinkMovementMethod());
return binding.getRoot();
}
示例27
@Override
public View getGroupView(int groupPosition, boolean isExpanded,View convertView, ViewGroup parent) {
MoodleCourseDetailsFragment.HeaderText header = (MoodleCourseDetailsFragment.HeaderText) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(header.getHeaderName());
return convertView;
}
示例28
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (Util.isLandscape(getResources())) {
impl = new LandscapeImpl(this);
} else {
impl = new PortraitImpl(this);
}
View view = inflater.inflate(R.layout.fragment_flat_player, container, false);
unbinder = ButterKnife.bind(this, view);
return view;
}
示例29
public CallsRecyclerViewAdapter(List<Call> callList, BaldActivity activity) {
this.callList = callList;
this.activity = activity;
this.inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final TypedValue typedValue = new TypedValue();
final Resources.Theme theme = activity.getTheme();
theme.resolveAttribute(R.attr.bald_decoration_on_button, typedValue, true);
textColorOnRegular = typedValue.data;
theme.resolveAttribute(R.attr.bald_background, typedValue, true);
this.letterContactBackground = new ColorDrawable(typedValue.data);
this.randomColorMaker = new RandomColorMaker(typedValue.data);
this.privateFace = activity.getDrawable(R.drawable.private_face_in_recent_calls);
this.face = activity.getDrawable(R.drawable.face_in_recent_calls);
}
示例30
public void setContentView(int layoutRes){
if(layoutRes!=0){
this.mainView= LayoutInflater.from(context).inflate(layoutRes,null);
}else{
this.mainView=null;
}
create();
}