I'm trying to follow Google's Android tutorial to create my first application, but either I'm looking in the wrong place or the tutorial is wrong/out of date for the latest version of Android Studio.
On the page I linked above, to add an onClick handler in the Design view of Studio, it contains the following instruction:
However, in the Attributes window, there is no onClick item. I could only add the onClick handler by editing the xml in text mode. Here's what my screen looks like when I have the button selected:
However, after I add the onclick event to the xml file, it does appear in the Attributes window.
Is the tutorial wrong, or am I doing something wrong?
I don't know what version android you used, but in Android Studio Chipmunk, you can see onclick property at Common Atttributes
If you don't see Common Attributes, please check icon setting below Design button
Related
I am profiling a new application I am working with. I can see the captured pink circle, I want to find out where the view is ,In which fragment and where the click listener is defined.
Here I can only see the activity information.
It's a big project.
If you are using the latest version of Android Studio, when hovering over the green bar near the top, there should be a tooltip showing the Activity and Fragment.
Regarding how to find out the View, have you tried Android Studio's Layout Inspector? I don't know a single-click way to locate the listener but it may be feasible once you locate the view.
newbie in Android studio. Using Android Studio 3.5.3 to create app and the Build is Successful
I have the default MainActivity and activity_main.xml
Problem:
when I clicked on the activity_main.xml
- The Design view empty. Thus I can not drag UI like Plain text or others onto the Design activity Layout
Made changes in Style.xml
added the Base in below:
1) style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"
but this does not work.
Need your help to solve this problem.
Thanks
#MikeBottle, There might be a couple of things going on here. It could be because your activity doesn't have theme assigned.
Please check this:
Note: In the design view, when you click the eye icon, it will give you the options to show / hide the layout decorations. It includes the top and bottom status bars. Please check if that changes anything.
Also, make sure the activity has theme assigned.
For the reference, I also included the layout preview to demonstrate how it look when show layout decorations is not checked.
TL;DR: Although I can edit component attributes directly in XML (sanity check — I'm sane) the Attributes inspector pane claims nothing is selected. I.e. "It doesn't work."
I added a CardView to the main layout. It does show up in the Component Tree and in the Design Editor. I select the CardView in the Component Tree pane, but the Attributes pane says "No component selected".
I'm using Android Studio 3.5.2 on MacOS 10.15.1. This happens with all three CardViews (see screenshot).
Clicking the Text tab shows the XML for all the components, including the (so-called) "non-selected" one. Direct edits I make on the CardView XML entity do have effect, and the app builds and runs correctly, with all three CardViews showing up and scrolling in the ScrollView. So this is probably not a gradle issue (thanks autocorrect, it's not a cradle problem either). It's more like the build process knows about the views, but not the edit process.
I re-created the project from scratch, with the same result.
I had the same problem today with a FloatingActionButton in Android Studio on macOS.
Restarting Android Studio was the solution for me.
I've looked at the suggested answers and none of them get the layout preview to render properly. I have tried changing the theme and lowering the API.
With "AppTheme" selected as the theme, the layout preview does not render elements properly and does not match the emulator. The error messages, .xml, emulator and layout preview are shown in the screenshot.
Please let me know what information is needed. I am new-ish to android studio.
// Edit
The solution given by Jadhu worked with my previous IDE version. However, I also wanted to see the Action Bar in the preview. I tried to use the solution listed in the Jadhu's link but it still did not show the Action Bar.
After updating the IDE, I no longer need to make any changes but the Action Bar still will not appear.
// Edit 2
Make the Action Bar appear by clicking the "Eye Symbol" drop-down on the upper-left corner of the preview and selecting Show Layout Decorations.
Go to your res/values/styles.xml and change the:
"style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar""
to
"style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar""
if it doesnt work, you may find the answer Here, please feel free to take a look.
I am using the home button of the main Activity of my IM app to allow the user to change their availability status. My app is using ActionBarSherlock, which falls back to the native implementation where supported.
However, the size of the tappable area is inconsistent between Android releases:
On Android 4.2.0 and before (including the compatibility library), only the icon is tappable:
On Android 4.2.1+, icon and activity name are tappable:
How can I make the tappable area consistently include icon and activity title on all versions of Android?
I am using ActionBarCompat (and you should probably update, if you haven't already), so this may not behave exactly the same. I wanted the full title to be clickable for using the navigation drawer. For some reason, using a custom logo instead of the text makes the whole thing automatically clickable, where only the icon could be clicked before:
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setLogo(R.drawable.im_title);
I don't know if it's possible to trigger that change while still using text with the default icon, but the setDisplay... methods and flags may be a good place to start looking.