Android 增加菜单的大小并添加图像?
我的应用程序中的以下活动是链接到其余活动的菜单:Android 增加菜单的大小并添加图像?,android,layout,menu,Android,Layout,Menu,我的应用程序中的以下活动是链接到其余活动的菜单: /** * Class containg avtivity that sets up a menu * which then opens other classes * @author Ross * */ public class Menu extends ListActivity{ //array that holds the list of names of what will be displayed on scre
/**
* Class containg avtivity that sets up a menu
* which then opens other classes
* @author Ross
*
*/
public class Menu extends ListActivity{
//array that holds the list of names of what will be displayed on screen in menu
String classes[] = { "ViewTimesTables", "Practice", "RandomTest","About"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//takes list or array adapter
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
}
/**
* Method that allows a class to be opened through the menu, dependent on what is clicked
*/
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
//**ADD COMMENT**
super.onListItemClick(l, v, position, id);
//Setting string equal to whatever position in the classes array
String className= classes[position];
try {
//Allows class to be opened dependent on what is clicked
Class ourClass = Class.forName("com.example.multapply." + className);
// set up new intent based off class variable
Intent ourIntent = new Intent(Menu.this, ourClass);
//Start the Activity
startActivity(ourIntent);
}
catch (ClassNotFoundException e) {
//log error
e.printStackTrace();
}
}
}
以下是屏幕当前的外观:
我想:
-稍微增加每个菜单项的大小
-采用交替配色方案,即先绿后白,而不是灰
-在菜单下为哮喘患者添加图像。
注意:此活动未链接到xml文件。这就是我发现这些更改很困难的原因。如果您的更改只能使用xml完成,那么您可以创建自己的行视图xml并将其传递给ArrayAdapter。在其他情况下,您应该实现自己的ListAdapter。它有一个getView方法,您可以在其中执行您提到的所有操作。请参阅:,要更改颜色,只需在xml中添加颜色代码Google HTML颜色代码 例如: 对于按钮:
<Button
android:textColor="#FFFFFF"
android:background="#FFFFFF"
这是一张单子
通过在xml文件中相应地设计布局来创建自定义listview。然后设置扩展BaseAdapter或listAdapter的适配器。在getview方法中,膨胀xml布局并进行所需的更改。 比如说,
class CustomAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder vh;
if(convertView == null) {
vh = new ViewHolder();
convertView = inflater.inflate(R.layout.list_item, null);
//put your code here
convertView.setTag(vh);
}else {
vh = (ViewHolder) convertView.getTag();
}
return convertView;
}
此活动未链接到xml文件?如果您想自定义它,则需要链接到xml文件。因此,我如何创建xml文件以链接到列表视图/适配器等?伙计,关于如何执行此操作,这里有数百个教程:好的,谢谢,我将研究它们!谢谢,为了进行我所说的更改,我将如何对xml布局进行编码?