我为页脚菜单制作了一个简单的 android 程序,用于学习目的,我想要的是当我选择页脚的 4 个菜单中的任何一个时,应更改所选菜单图像。我已经尝试如下,但它不起作用我已经放置了图像和问题也请检查一下:
代码是:
菜单.java p
ackage com.esp.therisemethod.uc;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.esp.therisemethod.R;
import com.esp.therisemethod.ui.ContactusActivity;
import com.esp.therisemethod.ui.InfoActivity;
import com.esp.therisemethod.ui.ProgressActivity;
import com.esp.therisemethod.ui.ProgressGraph;
public class Menu extends RelativeLayout implements OnClickListener {
public LinearLayout llfooterHome;
public LinearLayout llfooterGraph = null;
public LinearLayout llfooterInfo = null;
public LinearLayout llfooterContactUs = null;
public Context objContext;
public Menu(Context context) {
super(context);
objContext = context;
init();
}
public Menu(final Context context, AttributeSet attrs) {
super(context, attrs);
objContext = context;
init();
}
public void init() {
View view = LayoutInflater.from(objContext).inflate(R.layout.uc_menu,
this, true);
llfooterHome = (LinearLayout)view.findViewById(R.id.llfooterHome);
llfooterGraph = (LinearLayout) view.findViewById(R.id.llfooterGraph);
llfooterInfo = (LinearLayout) view
.findViewById(R.id.llfooterInfo);
llfooterContactUs = (LinearLayout) view
.findViewById(R.id.llfooterContactUs);
llfooterGraph.setOnClickListener(this);
llfooterInfo.setOnClickListener(this);
llfooterContactUs.setOnClickListener(this);
llfooterHome.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent intent = null;
switch (v.getId()) {
case R.id.llfooterHome:
intent = new Intent(objContext, ProgressActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
objContext.startActivity(intent);
break;
case R.id.llfooterGraph:
intent = new Intent(objContext, ProgressGraph.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
objContext.startActivity(intent);
break;
case R.id.llfooterInfo:
intent = new Intent(objContext, InfoActivity.class);
objContext.startActivity(intent);
break;
case R.id.llfooterContactUs:
intent = new Intent(objContext, ContactusActivity.class);
objContext.startActivity(intent);
break;
}
}
public void setSelectedTab(int selectTab) {
switch (selectTab) {
case 1:
llfooterHome.setBackgroundResource(R.drawable.home_active);
llfooterGraph.setBackgroundResource(R.drawable.graph_default);
llfooterInfo.setBackgroundResource(R.drawable.info_default);
llfooterContactUs.setBackgroundResource(R.drawable.contactus_default);
break;
case 2:
llfooterHome.setBackgroundResource(R.drawable.home_default);
llfooterGraph.setBackgroundResource(R.drawable.graph_active);
llfooterInfo.setBackgroundResource(R.drawable.info_default);
llfooterContactUs.setBackgroundResource(R.drawable.contactus_default);
break;
case 3:
llfooterHome.setBackgroundResource(R.drawable.home_default);
llfooterGraph.setBackgroundResource(R.drawable.graph_default);
llfooterInfo.setBackgroundResource(R.drawable.info_active);
llfooterContactUs.setBackgroundResource(R.drawable.contactus_default);
break;
case 4:
llfooterHome.setBackgroundResource(R.drawable.home_default);
llfooterGraph.setBackgroundResource(R.drawable.graph_default);
llfooterInfo.setBackgroundResource(R.drawable.info_default);
llfooterContactUs.setBackgroundResource(R.drawable.contactus_active);
break;
}
}
}