大家好,我只是 java android 的初学者,所以我开始使用 Listactivity 开发我的应用程序,其中没有布局,所以我需要将项目居中并将颜色和字体更改为特定字体我只是想知道有没有人可以帮助我做到这一点 我正在使用 Eclipse 我知道它是旧的而不是 Studio 谢谢
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this,android.R.layout.simple_selectable_list_item, classes));
//Set in the center
//Set the color of Listactivity
getListView().setBackgroundColor(Color.rgb(0, 154, 154));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Long idd = getListAdapter().getItemId(position);
//show toast
Context context = getApplicationContext();
CharSequence text = ""+idd;
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
//getListView().getItemAtPosition(position)
String url = "https://www.mysite"+idd+".mp3" ; // your URL here
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(url);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // might take long! (for buffering, etc)
mediaPlayer.start();
}