Giter VIP home page Giter VIP logo

Comments (11)

Hemanshu avatar Hemanshu commented on August 22, 2024

My Bad for ActionBarSherlock I was overriding the default theme. Adding shareStyle to Sherlock theme.

<style name="LocalTheme" parent="Theme.Sherlock.Light"> @style/Widget.Holo.Light.CompoundButton.Switch </style>

from android-switch-backport.

markostamcar avatar markostamcar commented on August 22, 2024

I'm getting the same exception but not sure what Hemanshu did exactly to fix it.

My Activity uses

android:theme="@style/Theme.NoAudibleSelection"

and this theme is defined as

<style name="Theme.NoAudibleSelection" parent="android:Theme.NoTitleBar.Fullscreen">
<item name="android:soundEffectsEnabled">false</item>
<item name="switchStyle">@style/Widget.Holo.CompoundButton.Switch</item>
</style>

from android-switch-backport.

ramdroid avatar ramdroid commented on August 22, 2024

Try parent="@android:style/Theme.NoTitleBar.Fullscreen"

from android-switch-backport.

markostamcar avatar markostamcar commented on August 22, 2024

Thanks for your quick reply. It started working all by itself without any changes when I restarted Eclipse. Was having a "Missing styles. Is the correct theme chosen for this layout?" error in the layout design GUI and now it seems to work OK. I'll comment if I figure out the real reason behind it.

from android-switch-backport.

cbmarc avatar cbmarc commented on August 22, 2024

I'm having this same issue but in a blank app. Target version is 4.0.3 while min version is 2.3.3. Same exact error.

from android-switch-backport.

markostamcar avatar markostamcar commented on August 22, 2024

Sorry, I wan't able to find out the exact reason, I just used Clean Project in Eclipse and also restarted it and it stopped crashing with no code modifications.

from android-switch-backport.

cbmarc avatar cbmarc commented on August 22, 2024

Damn, it has to be another thing... I have cleaned up all this stuff and no luck. Gonna create a new project now and see if it's working.
EDIT: New project and not working. Here is the detail of what I'm doing:

  • My activity layout (relative layout):

<org.jraf.android.backport.switchwidget.Switch
    android:id="@+id/switch2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
- Configure Build Path > Android > Library > Add: select the BoD project > Apply > OK. - Add the styles to themes.xml or styles.xml (doesn't matter). - Launch app... and crash!

Really hope I'm missing something.

from android-switch-backport.

hanspeide avatar hanspeide commented on August 22, 2024

To all of you who cannot get this to work:
Are you using Eclipse, or another IDE?

from android-switch-backport.

cbmarc avatar cbmarc commented on August 22, 2024

Eclipse. Although I finally solved the problem, have been quite busy lately... sorry for not posting back.

The problem was that for some reason, the style was not found, causing the switch to crush on load. Here I drop you a couple of lines:

In the constructor

public Switch(Context context, AttributeSet attrs, int defStyle) {

I changed the line

final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Switch, defStyle, 0);

to

final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Switch, defStyle, R.style.Widget_Holo_CompoundButton_Switch);

To force it getting the style. If I didn't do this the switch styles were'nt found in the typedarray and a nullpointer was thrown.

Hope this helps.

from android-switch-backport.

BoD avatar BoD commented on August 22, 2024

Just as a follow up, make sure you are actually using the theme that you declare! To do that you must reference it in your AndroidManifest.xml. I just updated the readme file to clarify this. Hope this helps.

from android-switch-backport.

quintos avatar quintos commented on August 22, 2024

I'm having the same issue. I'm using Switch in a custom Dialog. Solution from cbmarc solved it for me.

from android-switch-backport.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.