我已经定义了三个不同的类来处理标签图标。下面是 BaseActivity 类。
public class MainScreenPagerAdapter extends FragmentPagerAdapter implements TabBarView.IconTabProvider {
private int[] tab_icons =
{R.drawable.launcher_inactive,
R.drawable.chat_inactive,
R.drawable.t3_inactive,
R.drawable.launcher,
R.drawable.chat_active,
R.drawable.t3_active
};
然后在 TabView.java 中我定义了 setIcon 如下
public void setIcon(int resId) {
setIcon(getContext().getResources().getDrawable(resId));
}
由于getDrawable 已弃用,我认为这是我看不到标签图标的唯一问题
public class TabView extends LinearLayout {
private ImageView mImageView;
private TextView mTextView;
public TabView(Context context) {
this(context, null);
}
public TabView(Context context, AttributeSet attrs) {
this(context, attrs, android.R.attr.actionBarTabStyle);
}
public TabView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.actionBarTabTextStyle, outValue, true);
int txtstyle = outValue.data;
int pad = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources()
.getDisplayMetrics());
mImageView = new ImageView(context);
mImageView.setLayoutParams(new LayoutParams(100, LayoutParams.MATCH_PARENT));//hadi andaze icon taba
mImageView.setScaleType(ScaleType.CENTER_INSIDE);
mTextView = new TextView(context);
mTextView.setLayoutParams(new LayoutParams(50, LayoutParams.MATCH_PARENT));
mTextView.setGravity(Gravity.CENTER);
// mTextView.setCompoundDrawablePadding(pad);
mTextView.setTextAppearance(context, txtstyle);
;
this.addView(mImageView);
// this.addView(mTextView);
this.setLayoutParams(new LayoutParams(determineScreenDensity(), LayoutParams.MATCH_PARENT));
//this.setLayoutParams(new LayoutParams(150, LayoutParams.MATCH_PARENT));
}
public void setIcon(int resId) {
Log.i("Case+","" +resId);
setIcon(getContext().getResources().getDrawable(resId));
}
public void setIcon(Drawable icon) {
if (icon != null) {
mImageView.setVisibility(View.VISIBLE);
mImageView.setImageDrawable(icon);
} else {
mImageView.setImageResource(View.GONE);
Log.i("icon","null" +null);
}
}
public void setText(int resId, int ico) {
setText(getContext().getString(resId), ico);
}
public void setText(CharSequence text, int ico) {
mTextView.setText(text);
mTextView.setCompoundDrawablesWithIntrinsicBounds(ico, 0, 0, 0);
;
}
然后从 TabBarView.java 类调用 setIcon()
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
mSelectedTab = position;
mOffset = positionOffset;
invalidate();
if (delegatePageListener != null) {
delegatePageListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
}
if (position == 0) {
tabView1.setIcon(((IconTabProvider) pager.getAdapter()).getPageIconResId(3));
tabView1.setScaleX(1);
tabView1.setScaleY(1);
tabView2.setIcon(((IconTabProvider) pager.getAdapter()).getPageIconResId(1));
// tabView2.setScaleX(2);
// tabView2.setScaleY(2);
tabView3.setIcon(((IconTabProvider) pager.getAdapter()).getPageIconResId(2));
tabView3.setScaleX(1.1f);
tabView3.setScaleY(1.1f);
} else if (position == 1) {
tabView1.setIcon(((IconTabProvider) pager.getAdapter()).getPageIconResId(0));
tabView1.setScaleX(0.7f);
tabView1.setScaleY(0.7f);
// tabView1.setBackgroundResource(R.drawable.transparent_button_2);
tabView2.setIcon(((IconTabProvider) pager.getAdapter()).getPageIconResId(4));
//tabView2.setBackgroundResource(R.drawable.transparent_round_button);
//tabView2.setScaleX(2);
//tabView2.setScaleY(2);
tabView3.setIcon(((IconTabProvider) pager.getAdapter()).getPageIconResId(2));
tabView3.setScaleX(1.1f);
tabView3.setScaleY(1.1f);
// tabView3.setBackgroundResource(R.drawable.transparent_button_2);
} else if (position == 2) {
tabView1.setIcon(((IconTabProvider) pager.getAdapter()).getPageIconResId(0));
//tabView1.setBackgroundResource(R.drawable.transparent_button_2);
tabView2.setIcon(((IconTabProvider) pager.getAdapter()).getPageIconResId(1));
//tabView2.setBackgroundResource(R.drawable.transparent_button_2);
tabView3.setIcon(((IconTabProvider) pager.getAdapter()).getPageIconResId(5));
// tabView3.setBackgroundResource(R.drawable.transparent_round_button);
tabView3.setScaleX(1.7f);
tabView3.setScaleY(1.7f);
/*
LayoutParams params = new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
);
params.gravity = Gravity.CENTER;
params.setMargins(40,0,0,0);
tabView1.setLayoutParams(params);
tabView2.setLayoutParams(params);
tabView3.setLayoutParams(params);
// tabView2.setPadding(20,0,20,0);
//tabView3.setPadding(20,0,0,0);
*/
}
}
this question 中的解决方案不能应用于我的代码。如果您能帮我解决这个问题,我将不胜感激。
最佳答案
This work in my case
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
holder.thumbnail.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_launcher_background, context.getTheme()));
} else {
holder.thumbnail.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_launcher_background));
}
// as per you requirement
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setIcon(context.getResources().getDrawable(R.drawable.ic_launcher_background, context.getTheme()));
} else {
setIcon(context.getResources().getDrawable(R.drawable.ic_launcher_background));
}
关于android - 标签图标在棉花糖中消失了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48402129/
我试图使用yard记录一些Ruby代码,尽管我所做的正是所描述的here或here#@param[Integer]thenumberoftrials(>=0)#@param[Float]successprobabilityineachtrialdefinitialize(n,p)#initialize...end虽然我仍然得到这个奇怪的错误@paramtaghasunknownparametername:the@paramtaghasunknownparametername:success然后生成的html看起来很奇怪。我称yard为:$yarddoc-mmarkdown我做错了什么?
我有一个div,它根据表单是否正确提交而改变。我想知道是否可以检查类的特定元素?开始元素看起来像这样。如果输入不正确,添加错误类。 最佳答案 试试这个:browser.div(:id=>"myerrortest").class_name更多信息:http://watir.github.com/watir-webdriver/doc/Watir/HTMLElement.html#class_name-instance_method另一种选择是只查看具有您期望的类的div是否存在browser.div((:id=>"myerrortes
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
了解Rails缓存如何工作的人可以真正帮助我。这是嵌套在Rails::Initializer.runblock中的代码:config.after_initializedoSomeClass.const_set'SOME_CONST','SOME_VAL'end现在,如果我运行script/server并发出请求,一切都很好。然而,在我的Rails应用程序的第二个请求中,一切都因单元化常量错误而变得糟糕。在生产模式下,我可以成功发出第二个请求,这意味着常量仍然存在。我已通过将以上内容更改为以下内容来解决问题:config.after_initializedorequire'some_cl
我有这样的HTML代码:Label1Value1Label2Value2...我的代码不起作用。doc.css("first").eachdo|item|label=item.css("dt")value=item.css("dd")end显示所有首先标记,然后标记标签,我需要“标签:值” 最佳答案 首先,您的HTML应该有和中的元素:Label1Value1Label2Value2...但这不会改变您解析它的方式。你想找到s并遍历它们,然后在每个你可以使用next_element得到;像这样:doc=Nokogiri::HTML(
我有以下不起作用的代码:=form_for(resource,:as=>resource_name,:url=>session_path(resource_name),:html=>{:class=>"well"})do|f|=f.label:email=f.email_field:email=f.label:password=f.password_field:password-ifdevise_mapping.rememberable?%p=f.label:remember_me,:class=>"checkbox"=f.check_box:remember_me,:class=>"
我正在尝试消除使用Bootstrap3的Rails4元素中的glyphicon错误。我没有使用任何Bootstrapgem将其添加到Assets管道中。我手动将bootstrap.css和bootstrap.js添加到各自的app/assets目录下,分别添加到application.css和application.js什么的我现在在网络浏览器的控制台中看到以下内容:GEThttp://localhost:3000/fonts/glyphicons-halflings-regular.woff404(NotFound)localhost/:1GEThttp://localhost:30
我正在遍历数组中的一组标签名称,我想使用构建器打印每个标签名称,而不是求助于“我认为:builder=Nokogiri::XML::Builder.newdo|xml|fortagintagsxml.tag!tag,somevalendend会这样做,但它只是创建名称为“tag”的标签,并将标签变量作为元素的文本值。有人可以帮忙吗?这个看起来应该比较简单,我刚刚在搜索引擎上找不到答案。我可能没有以正确的方式提问。 最佳答案 尝试以下操作。如果我没记错的话,我添加了一个根节点,因为Nokogiri需要一个。builder=Nokogi
我有一个偏爱:如何将像o.office这样的值插入到属性中?value="#{o.office}"无效。 最佳答案 'type='text'/>或者你可以使用表单助手 关于ruby-on-rails-如何将变量值插入ERB模板中的HTML标签?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/6172174/
是否可以从Ruby中的HTMLblock中提取IMG标签(或只是IMG标签的src属性)?例如,如果我有一个HTMLblock,例如:Loremipsumdolorsitamet,laboreetdoloremagnaaliqua.Duisauteiruredolorinreprehenderitinvoluptatevelitessecillumdoloreeufugiatnullapariatur.我可以通过正则表达式或其他方法只提取IMG标签或该IMG标签的src吗?提前感谢您的任何建议! 最佳答案 使用Nokogiri:re