[英]I need to share a phrase that is randomly generated
我需要一個字符串來共享我的代碼,下面是隨機生成一個句子的代碼,並且不能共享或復制並粘貼所選短語。 對不起我的英語
public class MainActivity extends ActionBarActivity {
private TextView textViewNewId;
private Button buttonNewId;
private String[] frases = {
"First phrase", "second phrase", "third phrase"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
textViewNewId = (TextView) findViewById(R.id.textViewNewId);
buttonNewId = (Button) findViewById(R.id.buttonNewId);
buttonNewId.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Random randomico = new Random();
int numeroAleatorio = randomico.nextInt( frases.length );
textViewNewId.setText( frases[ numeroAleatorio ]);
}
});
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View vivew) {
fab();
// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
// .setAction("Action", null).show();
}
});
}
private void fab() { //sharing implementation here
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "AndroidSolved");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Now Learn Android with AndroidSolved clicke here to visit ");
startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
您可以將所選文本傳遞給您的意圖並進行共享。 我做以下事情:
public static void shareOnSocials(Context context , String shareThings) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, shareThings);
context.startActivity(Intent.createChooser(intent, "HOOORA"));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.