这是我的第一个应用程序,也是我第一次发帖,所以请多多包涵。
我正在尝试这样做,以便用户可以从更改皮肤屏幕中选择整个应用程序的背景颜色。但是,就我现在所拥有的而言,它只会改变活动的颜色,直到它回到主要活动。
这是更改皮肤屏幕的代码
package cs.pacificu.mypace;
import android.R.layout;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Layout;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class Skin extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
final String[] SKINS = new String[] {"Light", "Dark"};
super.onCreate(savedInstanceState);
setContentView(R.layout.playlist);
final ListView listView = (ListView) findViewById (R.id.playlists);
listView.setAdapter(new ArrayAdapter<String> (this,R.layout.single_list_item,SKINS));
listView.setTextFilterEnabled(true);
listView.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id)
{
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(),
((TextView) view).getText(), Toast.LENGTH_SHORT).show();
//
View layout = findViewById(R.layout.activity_main);
String selectedFromList = (listView.getItemAtPosition(position).toString ());
if (SKINS [0] == selectedFromList)
{
listView.setBackgroundColor(Color.CYAN);
//layout.setBackgroundColor(android.R.color.darker_gray);
}
else if (SKINS[1] == selectedFromList)
{
listView.setBackgroundColor(Color.BLACK);
//layout.setBackgroundColor(android.R.color.black);
}
//
finish();
}
});
}
}
这是主要的活动代码
package cs.pacificu.mypace;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
/*import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.MenuInflater;*/
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
startPlaylists(null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected (MenuItem item)
{
switch (item.getItemId()) {
case R.id.skin:
changeSkin();
return true;
case R.id.action_settings:
settingsList();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void startPlaylists (View view)
{
Intent intentPlaylists = new Intent();
intentPlaylists.setClassName("cs.pacificu.mypace", "cs.pacificu.mypace.Playlist");
intentPlaylists.setAction("@strings/action_playlists");
startActivity(intentPlaylists);
}
public void changeSkin ()
{
Intent intentSkin = new Intent();
intentSkin.setClassName("cs.pacificu.mypace", "cs.pacificu.mypace.Skin");
intentSkin.setAction("@strings/action_skin");
startActivity(intentSkin);
}
public void settingsList ()
{
Intent intentSettings = new Intent();
intentSettings.setClassName("cs.pacificu.mypace", "cs.pacificu.mypace.Settings");
intentSettings.setAction("@strings/action_settings");
startActivity(intentSettings);
}
}
谢谢!