On upgrade to Android Studio 3.1 there is no TimePicker in the layout editor palette.
Search doesn't find it.
In fact all of the picker controls seem to have vanished.
They were there in 3.0.
I am not sure where to find it in the selection menu but if you just need a time picker in your project you can select the Text
tab on the bottom of your activity.xml
file and paste the TimePicker xml.
<TimePicker
android:id="@+id/simpleTimePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner"/>
Then you can select which timePickerMode
you want if you want a clock then change spinner
with clock
.
Hope this helps.
The Android Studio 3.1 release notes state that
Palette in the Layout Editor has received many improvements
It also states that there was
Reorganization of categories for views and layouts.
So changes to this section were planned for this release. This makes me speculate that removal of the pickers is purposeful.
This reorganization of the palette was noticed prior to final release of Android Studio 3.1 and a bug was filed. Although the bug was assigned no comment was added.
One of the bugs submitted for this issue has been assigned to a Googler. Again this isn't an official sign either way.
As stated in the other answers, there is comment in the release notes about the improvements in the palette.
https://developer.android.com/studio/releases/index.html#layout_editor
For some unknown reason the @Widget annotation cannot be located in the project.
A dirty trick I made, is to create my own @Widget annotation copying their code and then add it to a custom class which inherits from TimePicker, of course this is just if you are eager to have it in the Palette of your project xD
example: Widget.java
package com.example.ctuser1.myapplication;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.SOURCE)
public @interface Widget {
}
MyTimePicker.java
package com.example.ctuser1.myapplication;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TimePicker;
@Widget
public class MyTimePicker extends TimePicker {
public MyTimePicker(Context context) {
super(context);
}
public MyTimePicker(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyTimePicker(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
Result:
来源:https://stackoverflow.com/questions/49519550/android-studio-3-1-where-is-the-timepicker-in-the-layout-editor