Unable to create a ToggleButton in Eclipse IDE for android

两盒软妹~` 提交于 2019-12-18 06:55:08

问题


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 and the only component that fails to load is ToggleButton. The problem is not project specific. It persists in every project I create.

Note: I have tried dragging it directly as well as using XML code to generate it. But it fails either way and the error is same.

Error :

Exception raised during rendering: -1
Exception details are logged in Window > Show View > Error Log
The graphics preview in the layout editor may not be accurate:
Different corner sizes are not supported in Path.addRoundRect. (Ignore for this session)
Path.isConvex is not supported. (Ignore for this session)

I have referred this question and tried to edit it but the edit was rejected. So please do not redirect me there.

I am using API 21. All the build tools are installed.


回答1:


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




回答2:


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.




回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/27961982/unable-to-create-a-togglebutton-in-eclipse-ide-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!