Android的Activity图标设置
我想给AccelWorld前加个图标,代码如下:protectedvoidonCreate(BundlesavedInstanceState){super.onCreat...
我想给Accel World前加个图标,代码如下:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Window win = getWindow(); win.requestFeature(Window.FEATURE_LEFT_ICON); setContentView(R.layout.activity_main); win.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_jing); Button btn = (Button)findViewById(R.id.button); btn.setOnClickListener(this);}
但是这个会报错 requestFeature() must be called before adding content
如果把Window win = getWindow(); win.requestFeature(Window.FEATURE_LEFT_ICON);放在第一行,虽然不报错,但没有任何效果,求高手给小弟解答,感激不尽 展开
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Window win = getWindow(); win.requestFeature(Window.FEATURE_LEFT_ICON); setContentView(R.layout.activity_main); win.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_jing); Button btn = (Button)findViewById(R.id.button); btn.setOnClickListener(this);}
但是这个会报错 requestFeature() must be called before adding content
如果把Window win = getWindow(); win.requestFeature(Window.FEATURE_LEFT_ICON);放在第一行,虽然不报错,但没有任何效果,求高手给小弟解答,感激不尽 展开
1个回答
展开全部
可以在AndroidManifest.xml文件的activity标签中加入图片android:icon=""
追问
我加在这里,运行后还是没有图标
追答
Window win = getWindow();
win.requestFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.activity_main);
win.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.app_icon);
我刚才试了下,你之前写是对的啊,看看是不是别的地方的问题
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询