まず、ボタンをクリックするとメディアを再生する簡単なプログラムを作成しました。私が持っている私のメインActivityクラスでMediaPlayerを目に見えないボタンにアタッチしたい
:
MediaPlayer mySound;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mySound = MediaPlayer.create(this, R.raw.sleepnk);
}
は、それから私は、次のように作成しました:
public void playMusic(View view)
{
mySound.start();
}
はその後、私のXMLファイルに私がボタンを作成して、コメントを追加:
android:onClick="playMusic"
を
今、アプリにメディアを追加しようとしていますが、そのようなものはありません:
<Button
android:id="@+id/button"
.
私の目標は、この新しいアプリで目に見えないボタン「を開始するには、をタップし、」しかし、どのボタンがXMLファイルに存在しないので、私はどこに私のplayMusic
方法を添付するかわからないこれにメディアファイルを追加することです開始ボタンをタップします。私はあなたがそれをボタン -
として機能しているか確認できるように含まれている値のフォルダの下のstrings.xmlがあり、ボタンを起動するタップのインスタンスを含めています:
<?xml version="1.0" encoding="utf-8"?>
<string name="app_name">Panoramik</string>
<string name="instruction_tap_start">Tap to start</string>
はその後、我々が持っているMainActivity.javaファイルに:
private View.OnClickListener mCameraOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mIsCapturing) {
//clear the flag to prevent the screen of being on
getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
if (mDMDCapture.finishShooting()) {
mIsStitching = true;
mTextViewInstruction.setVisibility(View.INVISIBLE);
}
mIsCapturing = false;
setInstructionMessage(R.string.instruction_tap_start);
私もsetInstructionMes」のためのコードを含むていますセージ」方法:
private void setInstructionMessage(int msgID)
{
if (mCurrentInstructionMessageID == msgID)
return;
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(mDisplayMetrics.widthPixels, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
if (msgID == R.string.instruction_empty || msgID == R.string.instruction_hold_vertically || msgID == R.string.instruction_tap_start
|| msgID == R.string.instruction_focusing) {
params.addRule(RelativeLayout.CENTER_VERTICAL);
} else {
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
}
mTextViewInstruction.setLayoutParams(params);
mTextViewInstruction.setText(msgID);
mCurrentInstructionMessageID = msgID;
}
誰もが、私は目に見えないボタンを起動するタップに私のメディアファイルsleepnkを添付することができる方法を教えてもらえますか?
EDIT:視覚障害者のためにアプリが作成されているため、基本的には「タップ・トゥ・スタート」と言ってもらいたいです。アプリに返信するように他の提案があれば、気軽にコメントしてください。