Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7797227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:37:07+00:00 2026-06-01T23:37:07+00:00

I try implement compound view for my dashboard activity. It’s Button with TextView .

  • 0

I try implement compound view for my dashboard activity. It’s Button with TextView. Need for my theme.
I have attr.xml file

<declare-styleable name="DashboardButton">
    <attr name="drawableTop" format="reference"/> <!-- i want set android:drawableTop of button-->
    <attr name="btnText" format="string" /> <!-- text about button functionality-->
    <attr name="tvText" format="string" /> <!-- additional information -->
</declare-styleable>

also have dashboard_button.xml layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

    <Button
        android:id="@+id/btn"
        style="@style/DashboardButton"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

    <TextView 
         style="@style/btn_add_info"
         android:id="@+id/txtView"
         android:text="0"/>
</RelativeLayout>

also have custom component DashboardButton

public class DashboardButton extends RelativeLayout {

private TextView txtView;
private Button btn;

public DashboardButton(Context context) {
    super(context);
}

public DashboardButton(Context context, AttributeSet attrs) {
    super(context, attrs);
    LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.dashboard_button, this);
    loadViews(attrs);
}

public DashboardButton(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.dashboard_button, this);
    loadViews(attrs);
}

private void loadViews(AttributeSet attrs) {
    txtView = (TextView) findViewById(R.id.txtView);
    btn = (Button) findViewById(R.id.btn);
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DashboardButton);
    txtView.setText(a.getString(R.styleable.DashboardButton_tvText));
    btn.setText(a.getString(R.styleable.DashboardButton_btnText));
   //i think issue here but can't understand what i should do
    Drawable topDrawable = a.getDrawable(R.styleable.DashboardButton_drawableTop); 
    btn.setCompoundDrawables(null, topDrawable, null, null);
    a.recycle();
}

public void setTxtViewText(CharSequence text) {
    txtView.setText(text);
}
}

and finally i have

    <my.package.name.DashboardButton
         android:id="@+id/Btn"
         style="@style/DashboardButton"
         app:btnText="@string/my_function"
         app:tvText="@string/add_info"
         app:drawableTop="@drawable/function_logo">
    </my.package.name.DashboardButton>

All work fine, except app:drawableTop drawable not load at run time, I dont see drawable. Can you help me by advice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:37:08+00:00Added an answer on June 1, 2026 at 11:37 pm

    You need to set the bounds for your drawable:

    topDrawable.setBounds( new Rect( 0, 0, w, h ) );
    

    or alternatively use:

    btn.setCompoundDrawablesWithIntrinsicBounds(null, topDrawable, null, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to implement file uploader script from this Github project and I need
If I try to implement my class on this file I get an error
I have android device with root and i try to implement some small app.
i have a big problem. i try to implement a kind of speedometer. i
I have made a Custom Component in XML, consisting of a button with an
I try to implement Hash join in Hadoop. However, Hadoop seems to have already
I try to implement a Google +1 button in my website, but for some
I try to implement php image verification code, here is in test.php file: <form
I try to implement callback interface with COM techonlogy and have IDL like that:
i am just try to implement the tutorial from here but i have problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.