In my android XML Graphical Layout, it can not display my ToggleButton
. I get some errors (see below). I have checked all other components in the Palette window
Perhaps it is the display theme so ensure that the theme you select matches the android:theme
in your activity
tag in AndroidManifest.xml
. In Android Studio (sorry not eclipse as per question) in the top bar of the preview panel, I had to click the current theme name (which was Light
) which brings up the Select Theme
panel and then choose my theme under Project Themes
(as I had a custom theme - you location may vary).
Problem is in your background drawable. Corners of your rectangle can be rounded all only by a same amount. Just like your error message says. You must set them all to same amount.
I think you can use this code
togglebut.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String text = togglebut.getText().toString();
Toast.makeText(MainActivity.this, "" + text, Toast.LENGTH_SHORT).show();
textView.setText(text);
}
});
for more info Click [here](http://androidcoding.in/2016/09/11/android-tutorial-toggle-button/"Android Toggle Button")
I had the same problem and solved by changing my target device screen to any of the xhdpi OR xxhdpi devices.
I'm sorry but I'm not able to post images yet, all you have to do is go to the dropdown menu just above the graphical layout -> General OR Google -> Select the xhdpi/xxhdpi target device you prefer.
I'm also new to android so I'm not able to explain why this is happening, I can only guess it's a compatibility issue or something. I'll try finding out more..
In the meantime I hope this will turn useful for you as well :-)