List of usage examples for android.content Context obtainStyledAttributes
public final TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes)
From source file:android.support.v13.app.FragmentTabHost.java
private void initFragmentTabHost(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.inflatedId }, 0, 0); mContainerId = a.getResourceId(0, 0); a.recycle();//from w w w .j av a 2 s .c o m super.setOnTabChangedListener(this); // If owner hasn't made its own view hierarchy, then as a convenience // we will construct a standard one here. if (findViewById(android.R.id.tabs) == null) { LinearLayout ll = new LinearLayout(context); ll.setOrientation(LinearLayout.VERTICAL); addView(ll, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); TabWidget tw = new TabWidget(context); tw.setId(android.R.id.tabs); tw.setOrientation(TabWidget.HORIZONTAL); ll.addView(tw, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0)); FrameLayout fl = new FrameLayout(context); fl.setId(android.R.id.tabcontent); ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0)); mRealTabContent = fl = new FrameLayout(context); mRealTabContent.setId(mContainerId); ll.addView(fl, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, 0, 1)); } }
From source file:cn.bproject.neteasynews.widget.FragmentTabHost.java
private void initFragmentTabHost(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.inflatedId }, 0, 0); mContainerId = a.getResourceId(0, 0); a.recycle();//w w w. j a v a 2 s .com super.setOnTabChangedListener(this); }
From source file:com.albedinsky.android.ui.widget.ActionTextButton.java
/** * Called from one of constructors of this view to perform its initialization. * <p>//ww w .ja va 2 s.com * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for * this view specific data from it that can be used to configure this new view instance. The * specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default data * from the current theme provided by the specified <var>context</var>. */ private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_ActionTextButton, defStyleAttr, defStyleRes); if (typedArray != null) { final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { final int index = typedArray.getIndex(i); if (index == R.styleable.Ui_ActionTextButton_android_text) { setText(typedArray.getText(index)); } else if (index == R.styleable.Ui_ActionTextButton_android_paddingLeft) { setPadding(typedArray.getDimensionPixelSize(index, 0), getPaddingTop(), getPaddingRight(), getPaddingBottom()); } else if (index == R.styleable.Ui_ActionTextButton_android_paddingRight) { setPadding(getPaddingLeft(), getPaddingTop(), typedArray.getDimensionPixelSize(index, 0), getPaddingBottom()); } } typedArray.recycle(); } }
From source file:android.support.design.widget.NavigationDrawerView.java
public NavigationDrawerView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // Custom attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NavigationDrawerView, defStyleAttr, R.style.Widget_Design_NavigationDrawerView); //noinspection deprecation setBackgroundDrawable(a.getDrawable(R.styleable.NavigationDrawerView_android_background)); ViewCompat.setElevation(this, a.getDimensionPixelSize(R.styleable.NavigationDrawerView_android_elevation, 0)); ViewCompat.setFitsSystemWindows(this, a.getBoolean(R.styleable.NavigationDrawerView_android_fitsSystemWindows, false)); mMaxWidth = a.getDimensionPixelSize(R.styleable.NavigationDrawerView_android_maxWidth, 0); a.recycle();/* ww w. j a va 2s. com*/ // Set up the menu mMenu = new MenuBuilder(context); mMenu.setCallback(new MenuBuilder.Callback() { @Override public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) { return mListener != null && mListener.onNavigationItemSelected(item); } @Override public void onMenuModeChange(MenuBuilder menu) { } }); mPresenter = new NavigationMenuPresenter(); mPresenter.setId(PRESENTER_NAVIGATION_DRAWER_VIEW); mPresenter.initForMenu(context, mMenu); mMenu.addMenuPresenter(mPresenter); addView((View) mPresenter.getMenuView(this)); }
From source file:android.support.v7.preference.MultiSelectListPreference.java
public MultiSelectListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MultiSelectListPreference, defStyleAttr, defStyleRes);/*from w ww . j a v a 2 s .c o m*/ mEntries = TypedArrayUtils.getTextArray(a, R.styleable.MultiSelectListPreference_entries, R.styleable.MultiSelectListPreference_android_entries); mEntryValues = TypedArrayUtils.getTextArray(a, R.styleable.MultiSelectListPreference_entryValues, R.styleable.MultiSelectListPreference_android_entryValues); a.recycle(); }
From source file:com.anlddev.customwidget.widget.AFragmentTabHost.java
private void initFragmentTabHost(Context context, AttributeSet attrs) { final TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.inflatedId }, 0, 0); mContainerId = a.getResourceId(0, 0); a.recycle();//from w w w . j a va 2s. c om super.setOnTabChangedListener(this); }
From source file:cn.thinkjoy.startup.widget.FragmentTabHost.java
private void initFragmentTabHost(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.inflatedId }, 0, 0); mContainerId = a.getResourceId(0, 0); a.recycle();/*from w w w. j a v a 2 s . com*/ super.setOnTabChangedListener(this); }
From source file:com.actionbarsherlock.internal.view.menu.ListMenuItemView.java
public ListMenuItemView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); mContext = context;//w ww . j a v a 2 s. co m TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockMenuView, defStyle, 0); mBackground = a.getDrawable(R.styleable.SherlockMenuView_itemBackground); mTextAppearance = a.getResourceId(R.styleable.SherlockMenuView_itemTextAppearance, -1); mPreserveIconSpacing = a.getBoolean(R.styleable.SherlockMenuView_preserveIconSpacing, false); mTextAppearanceContext = context; a.recycle(); }
From source file:android.support.v7.preference.DialogPreference.java
public DialogPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DialogPreference, defStyleAttr, defStyleRes);/*from ww w. j a v a2 s . c o m*/ mDialogTitle = TypedArrayUtils.getString(a, R.styleable.DialogPreference_dialogTitle, R.styleable.DialogPreference_android_dialogTitle); if (mDialogTitle == null) { // Fall back on the regular title of the preference // (the one that is seen in the list) mDialogTitle = getTitle(); } mDialogMessage = TypedArrayUtils.getString(a, R.styleable.DialogPreference_dialogMessage, R.styleable.DialogPreference_android_dialogMessage); mDialogIcon = TypedArrayUtils.getDrawable(a, R.styleable.DialogPreference_dialogIcon, R.styleable.DialogPreference_android_dialogIcon); mPositiveButtonText = TypedArrayUtils.getString(a, R.styleable.DialogPreference_positiveButtonText, R.styleable.DialogPreference_android_positiveButtonText); mNegativeButtonText = TypedArrayUtils.getString(a, R.styleable.DialogPreference_negativeButtonText, R.styleable.DialogPreference_android_negativeButtonText); mDialogLayoutResId = TypedArrayUtils.getResourceId(a, R.styleable.DialogPreference_dialogLayout, R.styleable.DialogPreference_android_dialogLayout, 0); a.recycle(); }
From source file:com.android.settings.SeekBarPreference.java
public SeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.ProgressBar, defStyleAttr, defStyleRes);//from www . ja va 2s . c o m setMax(a.getInt(com.android.internal.R.styleable.ProgressBar_max, mMax)); a.recycle(); a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.SeekBarPreference, defStyleAttr, defStyleRes); final int layoutResId = a.getResourceId(com.android.internal.R.styleable.SeekBarPreference_layout, com.android.internal.R.layout.preference_widget_seekbar); a.recycle(); setLayoutResource(layoutResId); }