在片段中使用Clock-Widget可能吗?

时间:2015-07-27 12:44:44

标签: android android-fragments android-widget

我的MainActivity中有一个片段,显示数字时钟。它有效:它显示当前的系统时间。但它看起来很简单。所以在我开始尝试设计这个时钟之前,我想问一下,如果有办法,可以使用系统Digital-Clock Widget?

小部件的屏幕截图,我想在我的片段中使用:

enter image description here

FragmentClock.java:

public class FragmentClock extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        View view = inflater.inflate(R.layout.fragment_clock, container, false);
        return view;
    }
}

fragment_clock.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayoutClockDisplay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#000000">
    <DigitalClock
        android:id="@+id/digital_clock"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="visible"/>

</LinearLayout>

0 个答案:

没有答案