private void afterInflate(int menuRes, Menu menu){ IconData root = new IconData(0, 0, 0); XmlResourceParser parser = null; try { parser = mContext.getResources().getLayout(menuRes); AttributeSet attrs = Xml.asAttributeSet(parser); parseMenu(parser, attrs, root); } catch (XmlPullParserException e) { throw new InflateException("Error inflating menu XML", e); } catch (IOException e) { throw new InflateException("Error inflating menu XML", e); } finally { if (parser != null) parser.close(); // populate the menu with the parsed icons populateIcons(menu, root, mDefaultColor); } }
AttributeSet as = null; Resources r = getResources(); XmlResourceParser parser = r.getLayout(R.layout.testcameraoverlay); int state = 0; do { try { state = parser.next(); } catch (XmlPullParserException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } if (state == XmlPullParser.START_TAG) { if (parser.getName().equals("TextView")) { as = Xml.asAttributeSet(parser); break; } } } while(state != XmlPullParser.END_DOCUMENT);
public final XmlResourceParser getLayout(@LayoutRes int resId) { return mContext.getResources().getLayout(resId); }
Resources r = getResources(); XmlResourceParser parser = r.getLayout(R.layout.your_layout); int state = 0; do { try { state = parser.next(); } catch (XmlPullParserException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } if (state == XmlPullParser.START_TAG) { //here get the attributes you want..., with AttributeSet for example } } } while(state != XmlPullParser.END_DOCUMENT);
private Map<Integer, MenuItemStrings> getMenuItemsStrings(Resources resources, int resId) { XmlResourceParser parser = resources.getLayout(resId); AttributeSet attrs = Xml.asAttributeSet(parser); try { return parseMenu(parser, attrs); } catch (XmlPullParserException | IOException e) { e.printStackTrace(); return new HashMap<>(); } }
private void initializeAttributeSet(@NonNull ViewGroup parent) { sParser = parent.getResources().getLayout(R.layout.layout_params_hack); //noinspection StatementWithEmptyBody try { //noinspection StatementWithEmptyBody while (sParser.nextToken() != XmlPullParser.START_TAG) { // Skip everything until the view tag. } } catch (XmlPullParserException | IOException e) { e.printStackTrace(); } }
private void initView(Context context, Resources resources, View content) { // TODO Auto-generated method stub setOrientation(LinearLayout.HORIZONTAL); this.mContext = context; this.mResources = resources; Log.i(TAG, "---1---"); mScroller = new Scroller(context); Log.i(TAG, "---2---"); View view = LayoutInflater.from(context).inflate(resources.getLayout(R.layout.slide_view_merge), this); Log.i(TAG, "---3---"); // view.findViewById(R.id.holder).setBackground(resources.getDrawable(R.drawable.selector_slider_holder)); Log.i(TAG, "---4---"); // shenhe = (TextView) view.findViewById(R.id.shenhe); // back = (TextView) findViewById(R.id.back); // back.setCompoundDrawablesWithIntrinsicBounds(null, resources.getDrawable(R.drawable.back), null, null); // back.setOnClickListener(this); // shenhe.setOnClickListener(this); mViewContent = (LinearLayout) view.findViewById(R.id.view_content); // mHolderWidth = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mHolderWidth, getResources().getDisplayMetrics())); mHolderWidth = getResources().getDimensionPixelSize(R.dimen.width_); if(content!=null){ mViewContent.addView(content); } }
XmlResourceParser xmlResourceLayout = packageResources.getLayout(id);
Drawable drawable = resources.getDrawable(id); }else if(resourceType.getName().equals(layoutClassName)){ XmlResourceParser layout = resources.getLayout(id);
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View mView = inflater.inflate( getResources().getLayout(R.layout.fragment_bannervp), container, false); initView(mView); setTestData(); return mView; }
public View inflate(int resource, ViewGroup root, boolean attachToRoot) { final Resources res = getContext().getResources(); if (DEBUG) { Log.d(TAG, "INFLATING from resource: \"" + res.getResourceName(resource) + "\" (" + Integer.toHexString(resource) + ")"); } final XmlResourceParser parser = res.getLayout(resource); try { return inflate(parser, root, attachToRoot); } finally { parser.close(); } }
private String getLayout(int id) { XmlResourceParser parser = mContext.getResources().getLayout(id); try { StringBuilder sb = new StringBuilder();
/** * Inflate a menu hierarchy from the specified XML resource. Throws * {@link InflateException} if there is an error. * * @param menuRes Resource ID for an XML layout resource to load (e.g., * <code>R.menu.main_activity</code>) * @param menu The Menu to inflate into. The items and submenus will be * added to this Menu. */ public void inflate(int menuRes, Menu menu) { XmlResourceParser parser = null; try { parser = mContext.getResources().getLayout(menuRes); AttributeSet attrs = Xml.asAttributeSet(parser); parseMenu(parser, attrs, menu); } catch (XmlPullParserException e) { throw new InflateException("Error inflating menu XML", e); } catch (IOException e) { throw new InflateException("Error inflating menu XML", e); } finally { if (parser != null) parser.close(); } }
/** * Inflate a menu hierarchy from the specified XML resource. Throws * {@link InflateException} if there is an error. * * @param menuRes Resource ID for an XML layout resource to load (e.g., * <code>R.menu.main_activity</code>) * @param menu The Menu to inflate into. The items and submenus will be * added to this Menu. */ public void inflate(int menuRes, Menu menu) { XmlResourceParser parser = null; try { parser = mContext.getResources().getLayout(menuRes); AttributeSet attrs = Xml.asAttributeSet(parser); parseMenu(parser, attrs, menu); } catch (XmlPullParserException e) { throw new InflateException("Error inflating menu XML", e); } catch (IOException e) { throw new InflateException("Error inflating menu XML", e); } finally { if (parser != null) parser.close(); } }
try { Resources resources = getPackageManager().getResourcesForApplication(packageName); XmlResourceParser xpp = resources.getLayout(prefsId); xpp.next(); String action = null;
public void inflateMenu(@MenuRes int menuRes) { if (menuRes == 0) return; getActivity().getMenuInflater() .inflate(menuRes, mActionMenu.getMenu()); XmlResourceParser parser = null; try { //noinspection ResourceType parser = getResources().getLayout(menuRes); AttributeSet attrs = Xml.asAttributeSet(parser); parseMenu(parser, attrs); } catch (XmlPullParserException | IOException e) { // should not happens throw new InflateException("Error parsing menu XML", e); } finally { if (parser != null) parser.close(); } }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(getResources().getLayout(R.layout.fragment_transaction), container, false); initListView(rootView); merchantXpub = PrefsUtil.getInstance(getActivity()).getValue(PrefsUtil.MERCHANT_KEY_MERCHANT_RECEIVER, ""); push_notifications = PrefsUtil.getInstance(getActivity()).getValue(PrefsUtil.MERCHANT_KEY_PUSH_NOTIFS, false); doBTC = PrefsUtil.getInstance(getActivity()).getValue(PrefsUtil.MERCHANT_KEY_CURRENCY_DISPLAY, false); btc_font = TypefaceUtil.getInstance(getActivity()).getTypeface(); swipeLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_container); swipeLayout.setProgressViewEndTarget(false, (int) (getResources().getDisplayMetrics().density * (72 + 20))); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { new GetDataTask().execute(); } }); swipeLayout.setColorScheme(R.color.blockchain_blue, R.color.blockchain_green, R.color.blockchain_dark_blue); thisActivity = getActivity(); return rootView; }