Android Studio 3.1 Where is the TimePicker in the Layout Editor

风格不统一 提交于 2019-12-03 23:31:33

问题


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.


回答1:


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.




回答2:


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.




回答3:


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

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