Tag: android-custom-view

Why view.onLayout() is called repetitively when changed=false?

From the official docs: Android Docs – View protected void onLayout (boolean changed, int left, int top, int right, int bottom) Parameters changed This is a new size or position for this view left Left position, relative to parent top Top position, relative to parent right Right position, relative to parent bottom Bottom position, relative […]

How to implement a CustomView with custom selector states?

I want to create a CustomView that displays an image. On click the view should change its state. There should be three states (off, set, notset) the view can represent. I want to do this with a selector in XML. It does not necesseraliy need to be a custom selector. I could reuse three states […]

State progressbar android

I’m looking for a smooth way to implement a “state” progressbar in Android like shown in the three examples below. As I’m not a fan of reinventing the wheel I’d like to ask if there is some library available I don’t know about. I looked it up and couldn’t find any lib so I guess […]

How to display the Html formatted text in the PopUp box using alert dialog builder?

I have using android alert dialog builder to display the some user message(String) as a pop up box to the user. Now, My requirement is the message box should be able to support HTML format for this message. Including, there may be a URL/link returned in this user message. Selecting this link should put the […]

How to create a circle clippath from an image?

Imagine that I have a rectangle image. How could I create a style like the next one? I mean, cropping the image into a circle, add the border, the shadow and the gross /shine effect. Until now, I only have tried this snippet code to crop the image: Cropping circular area from bitmap in Android […]

Unable to Add custom view to Android Action bar,why?

I am trying to add my custom view into Action bar. final View addView=getLayoutInflater().inflate(R.layout.home_actionbar_buttons, null); getActionBar().setCustomView(addView); my XML, <LinearLayout android:id=”@+id/linearLayout1″ xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_height=”wrap_content” android:layout_width=”match_parent”> <Button android:text=”Refresh” android:layout_height=”wrap_content” android:id=”@+id/btn_refresh” android:layout_width=”wrap_content”></Button> </LinearLayout but i get nullpointer exception. when i debug,addView object gets populated and its not null. is ViewGroupRoot mandatory while inflating? EDIT 1: Logcat 09-30 12:50:11.625: DEBUG/PackageManager(74): […]

Manually inflating custom view yields different layouts for ActionBar custom view

Custom view from resource: // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); actionBar.setCustomView(R.layout.custom_action_bar); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); the result is: Custom view manually inflated: // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.custom_action_bar, null); actionBar.setCustomView(view); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); the result is: custom_action_bar.xml: <?xml […]

Android registerOnSharedPreferenceChangeListener() causes crash in a Custom View

Whenever I try to add this line it crashes my app. Am I not putting it in the right spot? preferences.registerOnSharedPreferenceChangeListener(myActivity.this); Here is my class class Simulation extends View { // I declare my program variables here public Simulation(Context context) { super(context); // get the preferences SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences(context); preferences .registerOnSharedPreferenceChangeListener(myActivity.this); String storedPreference […]

Android: Cannot inflate custom view in Robolectric test

So this is a possible duplicate of this question: Testing custom Views with Robolectric But since that one doesn’t have an accepted answer, I’m going to ask again, with my own code examples. I’m using Robolectric 2.3 to run unit tests on a project which uses a custom view defined in a file called “here_now.xml” […]

Draw Bitmap in Custom ImageView and get the Co-ordinates of the ImageView irrespective of the device

I want to get the co-ordinates of the ImageView, Irrespective of device size. Is there any possible way !! I have tried to create specific size for the ImageView,Even specific size for the Parent View also ,but its not working. I have tried the following possible ways. int[] posXY = new int[2]; imageview.getLocationOnScreen(posXY); int MoveX […]

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.