我在手机上有一个带有1个按钮的应用程序。我想通过android服装触发这个按钮。我怎么能这样做?
java代码仍然是Android Studio创建的标准,我将禁止它们。
穿xml代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout
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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="br.com.teste.wearbuttonclick.WearMainActivity"
tools:deviceIds="wear"
android:background="#5c6bc0"
>
<TextView
android:id="@+id/clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:textColor="@android:color/white"
app:layout_box="all" />
**<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:text="Click"
android:background="#5c6bc0"
android:textColor="#ffffff"
android:id="@+id/wearbutton"
/>**
</android.support.wearable.view.BoxInsetLayout>
移动xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="br.com.teste.wearbuttonclick.MobileMainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Target Button"
android:id="@+id/mobilebutton"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
答案 0 :(得分:0)
你好点击可穿戴的app按钮发送消息,在手持设备onMessageReceived()中用你的按钮名称调用这个方法: -
private void makeClick() {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "clicked", Toast.LENGTH_LONG).show();
}
});
button.performClick();
}