4
단추가있는 레이아웃이 있습니다. 버튼을 클릭하면 ShareActionProvider를 사용하여 구현할 수있는 '작업 표시 줄 공유 버튼'과 동일한 기능을 사용할 수 있습니다. 웹에서 예제를 찾고 있습니다. 그러나 하나를 찾을 수 없습니다. 이것이 가능한가?레이아웃에서 단추가있는 ShareActionProvider 사용
단추가있는 레이아웃이 있습니다. 버튼을 클릭하면 ShareActionProvider를 사용하여 구현할 수있는 '작업 표시 줄 공유 버튼'과 동일한 기능을 사용할 수 있습니다. 웹에서 예제를 찾고 있습니다. 그러나 하나를 찾을 수 없습니다. 이것이 가능한가?레이아웃에서 단추가있는 ShareActionProvider 사용
예, 버튼 클릭에 대한 응답으로 암시 적 인 텐트를 실행하여 동일한 기능을 수행 할 수 있습니다. 아래의 예처럼 : 희망
<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"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="31dp"
android:text="@string/MS1"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="36dp"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:onClick="SHARE"
android:text="SEND" />
</RelativeLayout>
layout_main.java
public class MAIN extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void SHARE(View view) {
// Do something in response to button
EditText content = (EditText) findViewById(R.id.editText1);
String shareBody = content.getText().toString();
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "\n\n");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.a5)));
}
}
Main.java이 도움이됩니다.