Unable to create a ToggleButton in Eclipse IDE for android

后端 未结 4 428
轻奢々
轻奢々 2020-12-19 16:31

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

相关标签:
4条回答
  • 2020-12-19 17:01

    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).

    0 讨论(0)
  • 2020-12-19 17:11

    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.

    0 讨论(0)
  • 2020-12-19 17:11

    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")

    0 讨论(0)
  • 2020-12-19 17:13

    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 :-)

    0 讨论(0)
提交回复
热议问题