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

  • Home
  • SEARCH
  • 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 6894485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:47:19+00:00 2026-05-27T06:47:19+00:00

I am trying to create a dashboard layout. It is different from the google

  • 0

I am trying to create a dashboard layout. It is different from the google i/o’s dashboard in the sense that the background of the image icon and the text below the icon is different.

In other words, the icon(image only) has a StateListDrawable for its background while the text has a transparent background. One way of doing this is to put this combination of the image and text in a LinearLayout and use it in the dashboard layout for each of the item which seems not-so-simple. Is this the only way I could do it? or is there a better and simple solution?

Update : You can take the project setup from here and experiment.

  • The layout file dashboard2.xml is using the google’s DashboardLayout class. In the main activity I’m just setting the contents of the view to be dashboard2

  • In that project you will find a statelist drawable in the drawable folder by the name dashboard_icon_bg_selector.xml. I want the background of all the dashboard icons to be this statelist drawable.

Any suggestion is appreciated.

  • 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-05-27T06:47:19+00:00Added an answer on May 27, 2026 at 6:47 am

    One possible solution I can think of is to use a LayerDrawable as your TextView’s topDrawable. I’ll outline the idea, enumerate some details and attach a link to the modified example project below.

    Code for a Button (in the layout file):

    <Button android:id="@+id/home_btn_schedule"
        style="@style/DPDashBoardButton"
        android:text="button 1"
        android:drawableTop="@drawable/dashboard_icon_bg_selector" />
    

    Two LayerDrawables, one for the ‘pressed/focussed/selected’ state and one for every other state (rest):

    dashboard_icon_layer_background_selected.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/dashboard_icon_background_selected" />
        <item android:bottom="14dip">
            <bitmap android:src="@drawable/btn_star_big_on_pressed"
                android:gravity="center" />
        </item>
    </layer-list>
    

    dashboard_icon_layer_background_rest.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/dashboard_icon_background_rest" />
        <item android:bottom="14dip">
            <bitmap android:src="@drawable/btn_star_big_on_rest"
                android:gravity="center" />
        </item>
    </layer-list>
    

    Some particularities for this specific example:

    • The reason why the star images are referenced as a bitmap is to prevent Android from scaling them to the container’s full width and height. The bottom distance is added to actually center the star with respect to the background image (textSize=12, plus 2 for padding), which, to be honest, is quite ugly to hardcode like this. Without this offset, the centered gravity will put the star image inside the center of the whole container, so including the space the text adds.
    • As such, replacing the item with the bitmap by <item android:drawable="@drawable/btn_star_big_on_rest" />, will result in the star image being scaled up. Just try it once to understand the effect.
    • This phenomenon is quite unfortunate, since we could potentially reference another xml drawable with above, taking advantage of all it’s already defined states! That’s why I actually had to copy over two of the star images from the Android repository: you cannot reference an xml drawable as a bitmap source and the actual images cannot be publicly referenced either. Try replacing the bitmap definition with <item android:drawable="@android:drawable/btn_star" /> to see the image getting scaled up, but keep the predefined states intact.
    • You could potentially workaround the scaling issue by creating 9patches out of the star images, making a StateListDrawable for the different states and reference the resulting xml drawable in a layer item. Although Android will still stretch the whole image to the container’s full size, the 9patches can make sure only transparent pixels are getting scaled.
    • // Edit: I realised there’s another limitation to this approach, as tapping the text will not make the state of the icon change. This might be what you’re after, but personally I’d say that from a user perspective it would make sense to have the whole thing respond to touch events…

    Hope this makes sense! Just to show you the result: left is all in rest state, right is topleft button being pressed.

    Zipped project here.

    Modified example project

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a blog dashboard that will connect to your Analytics
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create my first iPhone app that would play back audio. When I
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different
Trying to create a small monitor application that displays current internet usage as percentage
I am trying to create a dashboard for Dynamics CRM 4.0 using the telerik
Using the Roles dashboard, I can create Facebook test user accounts but when trying
I'm working on a google analytics dashboard for a CMS I've created. I'm trying
I trying create a class derivated from System.Web.UI.Page and in override Render i set
Trying to create a simple plugin that simply connects to an ftp site, looks

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.