Example usage for android.widget TextView setCompoundDrawablesWithIntrinsicBounds

List of usage examples for android.widget TextView setCompoundDrawablesWithIntrinsicBounds

Introduction

In this page you can find the example usage for android.widget TextView setCompoundDrawablesWithIntrinsicBounds.

Prototype

@android.view.RemotableViewMethod
public void setCompoundDrawablesWithIntrinsicBounds(@Nullable Drawable left, @Nullable Drawable top,
        @Nullable Drawable right, @Nullable Drawable bottom) 

Source Link

Document

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.

Usage

From source file:org.shaolin.uimaster.app.ui.MainActivity.java

private void initTabs() {
    MainTab[] tabs = MainTab.values();/*w  w w.  ja v a 2  s . c  o  m*/
    final int size = tabs.length;
    for (int i = 0; i < size; i++) {
        MainTab mainTab = tabs[i];
        TabSpec tab = mTabHost.newTabSpec(getString(mainTab.getResName()));
        View indicator = LayoutInflater.from(getApplicationContext()).inflate(R.layout.tab_indicator, null);
        TextView title = (TextView) indicator.findViewById(R.id.tab_title);
        Drawable drawable = this.getResources().getDrawable(mainTab.getResIcon());
        title.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
        title.setText(getString(mainTab.getResName()));
        tab.setIndicator(indicator);
        tab.setContent(new TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                return new View(MainActivity.this);
            }
        });
        Bundle bundle = new Bundle();
        bundle.putInt("FunctionId", i);
        bundle.putInt("id", i);
        bundle.putString("_chunkname", "org.shaolin.vogerp.commonmodel.diagram.ModularityModel");
        if (mainTab == MainTab.MAIN) {
            bundle.putString("_nodename", "OnlineOrderList");
            bundle.putString("_page", "org.shaolin.vogerp.ecommercial.page.OnlineOrderList");
            bundle.putString("_framename", "onlineOrderList");
        } else if (mainTab == MainTab.ORDER) {
            bundle.putString("_nodename", "OrderManagement");
            bundle.putString("_page", "org.shaolin.vogerp.ecommercial.page.OrderManagement");
            bundle.putString("_framename", "goldenOrderManager");
        } else if (mainTab == MainTab.PRODUCT) {
            bundle.putString("_nodename", "ProductManagement");
            bundle.putString("_page", "org.shaolin.vogerp.productmodel.page.ProductManagement");
            bundle.putString("_framename", "productManager");
        }
        mTabHost.addTab(tab, mainTab.getClz(), bundle);

        if (MainTab.ME == mainTab) {
            View cn = indicator.findViewById(R.id.tab_mes);
            mBvNotice = new BadgeView(MainActivity.this, cn);
            mBvNotice.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
            mBvNotice.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
            mBvNotice.setBackgroundResource(R.drawable.notification_bg);
            mBvNotice.setGravity(Gravity.CENTER);
        }
        mTabHost.getTabWidget().getChildAt(i).setOnTouchListener(this);
    }
}

From source file:io.github.hidroh.materialistic.DrawerActivity.java

@SuppressWarnings("ConstantConditions")
private void setUpDrawer() {
    mDrawerAccount.setOnClickListener(v -> showLogin());
    mDrawerLogout.setOnClickListener(v -> confirmLogout());
    View moreContainer = findViewById(R.id.drawer_more_container);
    TextView moreToggle = (TextView) findViewById(R.id.drawer_more);
    moreToggle.setOnClickListener(v -> {
        if (moreContainer.getVisibility() == View.VISIBLE) {
            moreToggle.setTextColor(ContextCompat.getColor(DrawerActivity.this,
                    AppUtils.getThemedResId(DrawerActivity.this, android.R.attr.textColorTertiary)));
            moreToggle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_expand_more_white_24dp, 0, 0, 0);
            moreContainer.setVisibility(View.GONE);
        } else {//from  www  .j a  va  2 s  .  co m
            moreToggle.setTextColor(ContextCompat.getColor(DrawerActivity.this,
                    AppUtils.getThemedResId(DrawerActivity.this, android.R.attr.textColorSecondary)));
            moreToggle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_expand_less_white_24dp, 0, 0, 0);
            moreContainer.setVisibility(View.VISIBLE);
        }
    });
    findViewById(R.id.drawer_list).setOnClickListener(v -> navigate(ListActivity.class));
    findViewById(R.id.drawer_best).setOnClickListener(v -> navigate(BestActivity.class));
    findViewById(R.id.drawer_popular).setOnClickListener(v -> navigate(PopularActivity.class));
    findViewById(R.id.drawer_new).setOnClickListener(v -> navigate(NewActivity.class));
    findViewById(R.id.drawer_show).setOnClickListener(v -> navigate(ShowActivity.class));
    findViewById(R.id.drawer_ask).setOnClickListener(v -> navigate(AskActivity.class));
    findViewById(R.id.drawer_job).setOnClickListener(v -> navigate(JobsActivity.class));
    findViewById(R.id.drawer_settings).setOnClickListener(v -> navigate(SettingsActivity.class));
    findViewById(R.id.drawer_favorite).setOnClickListener(v -> navigate(FavoriteActivity.class));
    findViewById(R.id.drawer_submit).setOnClickListener(v -> navigate(SubmitActivity.class));
    findViewById(R.id.drawer_user).setOnClickListener(v -> {
        Bundle extras = new Bundle();
        extras.putString(UserActivity.EXTRA_USERNAME, Preferences.getUsername(this));
        navigate(UserActivity.class, extras);
    });
    findViewById(R.id.drawer_feedback).setOnClickListener(v -> navigate(FeedbackActivity.class));

}

From source file:com.vv.androidreview.ui.activites.MainActivity.java

/** 
 * @param indicator1/*www . j  av a2s.c  om*/
 * @return
 */
private View getIndicatorView(Indicator indicator1) {
    View view = LayoutInflater.from(this).inflate(R.layout.tab_indicator, null);
    TextView indicator = (TextView) view.findViewById(R.id.tab_title);

    indicator.setText(getString(indicator1.getResName()));

    indicator.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
    Drawable icon = this.getResources().getDrawable(indicator1.getResIcon());
    //        ICON?
    //        icon.setBounds(0, 0, 75, 75);
    //        indicator.setCompoundDrawables(null,icon,null,null);
    indicator.setCompoundDrawablePadding(3);
    indicator.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
    indicator.setPadding(0, 8, 0, 5);

    return view;
}

From source file:com.ntsync.android.sync.activities.MainActivity.java

private void initViewPeopleBtn() {
    TextView startBtn = (TextView) findViewById(R.id.btnPeople);
    Intent contactAppIntent = ContactManager.createContactAppIntent();
    boolean isIntentSafe = false;
    if (contactAppIntent != null) {
        PackageManager packageManager = getPackageManager();
        List<ResolveInfo> activities = packageManager.queryIntentActivities(contactAppIntent, 0);
        isIntentSafe = !activities.isEmpty();

        Drawable icon = ContactManager.getContactAppIcon(this, contactAppIntent);
        startBtn.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
    }/*from  ww  w  .  j  av  a  2 s  . co  m*/
    startBtn.setEnabled(isIntentSafe);
}

From source file:com.ds.avare.utils.FolderPreference.java

/**
 * /*from  w  w w  .j ava  2s . c om*/
 */
private void loadFileList() {

    /*
     * Checks whether mPath exists
     */
    if (mPath.exists()) {
        FilenameFilter filter = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String filename) {
                File sel = new File(dir, filename);
                /*
                 * Filters based on whether the file is hidden or not, and is a folder
                 */
                return (!sel.isHidden());
            }
        };

        String[] fList = mPath.list(filter);
        if (fList == null) {
            fList = new String[0];
        }
        mFileList = new Item[fList.length];
        for (int i = 0; i < fList.length; i++) {
            mFileList[i] = new Item(fList[i], android.R.drawable.alert_light_frame);

            /*
             * Convert into file mPath
             */
            File sel = new File(mPath, fList[i]);

            /*
             * Set drawables
             */
            if (sel.isDirectory()) {
                if (sel.canWrite()) {
                    mFileList[i].icon = android.R.drawable.ic_menu_save;
                } else {
                    mFileList[i].icon = android.R.drawable.ic_lock_lock;
                }
            }
            /*
             * File is for information only
             */
            else {
                mFileList[i].icon = android.R.drawable.alert_light_frame;
            }
        }

        if (!mFirstLevel) {
            Item temp[] = new Item[mFileList.length + 1];
            for (int i = 0; i < mFileList.length; i++) {
                temp[i + 1] = mFileList[i];
            }
            temp[0] = new Item(mContext.getString(R.string.Up), android.R.drawable.ic_menu_revert);
            mFileList = temp;
        }
    }

    if (mFileList == null) {
        return;
    }
    /*
     * Set the adapter with file list
     */
    mAdapter = new ArrayAdapter<Item>(mContext, android.R.layout.select_dialog_item, android.R.id.text1,
            mFileList) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            /*
             * creates view
             */
            View view = super.getView(position, convertView, parent);
            TextView textView = (TextView) view.findViewById(android.R.id.text1);

            /* 
             * put the image on the text view
             */
            textView.setCompoundDrawablesWithIntrinsicBounds(mFileList[position].icon, 0, 0, 0);

            /*
             *  add margin between image and text (support various screen
             */
            textView.setCompoundDrawablePadding(10);
            textView.setTextColor(Color.parseColor("#FF71BC78"));
            return view;
        }
    };

    /*
     * Show where we are
     */
    mPathView.setText(mPath.getAbsolutePath());
}

From source file:com.ekuater.labelchat.ui.widget.PagerSlidingTabStrip.java

private void addIconTextTab(final int position, String title, int icon) {
    TextView tab = new TextView(getContext());
    tab.setText(title);/*from  w ww. j  a  v  a 2s  .c o  m*/
    tab.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(icon), null, null);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    addTab(position, tab);
}

From source file:com.irccloud.android.activity.EditConnectionActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_connection);

    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    getSupportActionBar().setCustomView(R.layout.actionbar_edit_connection);
    getSupportActionBar().setElevation(0);

    TextView t = findViewById(R.id.action_cancel);
    Drawable d;// ww  w .j  a  v  a  2  s  .  c o m
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        d = VectorDrawableCompat.create(getResources(), R.drawable.ic_action_cancel, null).mutate();
    else
        d = getResources().getDrawable(R.drawable.ic_action_cancel, null).mutate();
    d.setColorFilter(ColorScheme.getInstance().navBarHeadingColor, PorterDuff.Mode.SRC_ATOP);
    t.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);

    t = findViewById(R.id.action_done);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        d = VectorDrawableCompat.create(getResources(), R.drawable.ic_action_save, null).mutate();
    else
        d = getResources().getDrawable(R.drawable.ic_action_save, null).mutate();
    d.setColorFilter(ColorScheme.getInstance().navBarHeadingColor, PorterDuff.Mode.SRC_ATOP);
    t.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    final EditConnectionFragment newFragment = new EditConnectionFragment();
    if (getIntent() != null && getIntent().hasExtra("cid")) {
        newFragment.setCid(getIntent().getIntExtra("cid", -1));
        cid = getIntent().getIntExtra("cid", -1);
    }
    if (getIntent() != null && getIntent().hasExtra("hostname"))
        newFragment.default_hostname = getIntent().getStringExtra("hostname");
    if (getIntent() != null && getIntent().hasExtra("channels"))
        newFragment.default_channels = getIntent().getStringExtra("channels");
    newFragment.default_port = getIntent().getIntExtra("port", 6667);
    ft.replace(R.id.EditConnectionFragment, newFragment);
    ft.commit();

    getSupportActionBar().getCustomView().findViewById(R.id.action_cancel)
            .setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (ServersList.getInstance().count() < 1) {
                        NetworkConnection.getInstance().logout();
                        Intent i = new Intent(EditConnectionActivity.this, LoginActivity.class);
                        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(i);
                    }
                    finish();
                }

            });

    getSupportActionBar().getCustomView().findViewById(R.id.action_done)
            .setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    reqid = newFragment.save();
                }

            });

    NetworkConnection.getInstance().addHandler(this);
}

From source file:github.madmarty.madsonic.util.ImageLoader.java

@SuppressWarnings("deprecation")
private void setImage(View view, Drawable drawable, boolean crossfade) {
    if (view instanceof TextView) {
        // Cross-fading is not implemented for TextView since it's not in use.  It would be easy to add it, though.
        TextView textView = (TextView) view;
        textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
    } else if (view instanceof ImageView) {
        ImageView imageView = (ImageView) view;
        if (crossfade) {

            Drawable existingDrawable = imageView.getDrawable();
            if (existingDrawable == null) {
                Bitmap emptyImage;/*from ww w . j  av  a 2  s. co m*/
                if (drawable.getIntrinsicWidth() > 0 && drawable.getIntrinsicHeight() > 0) {
                    emptyImage = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                            drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
                } else {
                    emptyImage = Bitmap.createBitmap(imageSizeDefault, imageSizeDefault,
                            Bitmap.Config.ARGB_8888);
                }
                existingDrawable = new BitmapDrawable(emptyImage);
            } else {
                // Try to get rid of old transitions
                try {
                    TransitionDrawable tmp = (TransitionDrawable) existingDrawable;
                    int layers = tmp.getNumberOfLayers();
                    existingDrawable = tmp.getDrawable(layers - 1);
                } catch (Exception e) {
                    // Do nothing, just means that the drawable is a flat image
                }
            }

            Drawable[] layers = new Drawable[] { existingDrawable, drawable };

            TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
            imageView.setImageDrawable(transitionDrawable);
            transitionDrawable.startTransition(250);
        } else {
            imageView.setImageDrawable(drawable);
        }
    }
}

From source file:com.shome.app.PagerSlidingTabStrip.java

private void addIconTextTab(final int position, Drawable resDrawable, CharSequence title) {
    TextView tab = new TextView(getContext());
    tab.setCompoundDrawablesWithIntrinsicBounds(null, resDrawable, null, null);
    tab.setHeight(25);/* w  ww . jav  a2s .c om*/
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    //tab.
    //tab.setElevation(50);
    addTab(position, tab);
}

From source file:org.telegram.ui.LocationActivity.java

@Override
public void applySelfActionBar() {
    if (parentActivity == null) {
        return;/*from w ww .  ja v a2 s  . c  o m*/
    }
    ActionBar actionBar = parentActivity.getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setSubtitle(null);
    actionBar.setDisplayShowCustomEnabled(false);
    actionBar.setCustomView(null);
    if (messageObject != null) {
        actionBar.setTitle(LocaleController.getString("ChatLocation", R.string.ChatLocation));
    } else {
        actionBar.setTitle(LocaleController.getString("ShareLocation", R.string.ShareLocation));
    }

    TextView title = (TextView) parentActivity.findViewById(R.id.action_bar_title);
    if (title == null) {
        final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android");
        title = (TextView) parentActivity.findViewById(subtitleId);
    }
    if (title != null) {
        title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        title.setCompoundDrawablePadding(0);
    }
}