Through the previous study, we have set up the environment, so that we can be really developed.
First, create the Wear project
With the Project Creation Wizard, you can create good one wear projects step-by-step:
1. Create a new project, fill in the application name, application package name, project location, and get familiar with Android.
2. Here we choose the Wear SDK
3. Create a wearactivity to activate the activity portal
4. With a good name, we can do it by default.
Second, correction error
Wait a moment as to help you set up the project, but you will find an error.
System can not find watchactivity, here I Google A, got the answer wear support library is not this watchactivity, only insetactivity.
So as long as we replace the watchactivity with insetactivity, then we will prompt you to ovveride the Onreadyforcontent method, and then cut the oncreate into here to run the
Third, edit the code
The code is as follows Myactivity.java
PackageCom.example.bvin.androidwear_helloworld;ImportAndroid.os.Bundle;Importandroid.support.wearable.activity.InsetActivity;Importandroid.support.wearable.view.WatchViewStub;ImportAndroid.util.Log;ImportAndroid.widget.TextView; Public classMyActivityextendsinsetactivity {PrivateTextView Mtextview; Private StaticString TAG = "MyActivity"; @Override Public voidonreadyforcontent () {Setcontentview (r.layout.activity_my); FinalWatchviewstub stub =(watchviewstub) Findviewbyid (r.id.watch_view_stub); Stub.setonlayoutinflatedlistener (NewWatchviewstub.onlayoutinflatedlistener () {@Override Public voidonlayoutinflated (watchviewstub stub) {Mtextview=(TextView) Stub.findviewbyid (R.id.text); LOG.D (TAG,"TextView:" + mtextview.gettext () + "view=" +Mtextview); } }); } @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); }}
Activity_my.xml
<?XML version= "1.0" encoding= "Utf-8"?><Android. Support.wearable.view.WatchViewStub xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:app= "Http://schemas.android.com/apk/res-auto"Xmlns:tools= "Http://schemas.android.com/tools"Android:id= "@+id/watch_view_stub"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"App:rectlayout= "@layout/rect_activity_my"App:roundlayout= "@layout/round_activity_my"Tools:context=". MyActivity "Tools:deviceids= "Wear"></android.support.wearable.view.WatchViewStub>
Notice here that there is a rectlayout a roundlayout, a circular table layout, a square table layout.
Iv. Creating the simulator
This is no problem, you can run the boot simulator directly, this simulator is very fun.
Create a round simulator
Start, boot a series of tutorials, this interface beautiful dead
You can double-click to open this interface point start to find your own program
Five, the operation
Well, the simulator is square?