第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

為什么xml里面顯示不出自定義的按鈕和TextView

public?class?MyView?extends?RelativeLayout?{

????private?Button?rightBtn,LeftBtn;
????private?TextView?tvTitle;

????private?String?TitleText;
????private?float?TitleSize;
????private?int?TitleColor;

????private?String?LeftText;
????private?Drawable?leftBackground;
????private?int?LeftColor;

????private?String?rightText;
????private?Drawable?rightBackground;
????private?int?rightColor;
????
????private?LayoutParams?leftParams,rightParams,TitleParmas;

????public?MyView(Context?context,?AttributeSet?attrs)?{
????????super(context,?attrs);

????????TypedArray?ta?=?context.obtainStyledAttributes(attrs,R.styleable.TopBar);

????????LeftText??=?ta.getString(R.styleable.TopBar_LeftTitle);
????????leftBackground?=?ta.getDrawable(R.styleable.TopBar_LeftTitleBackground);
????????LeftColor?=?ta.getColor(R.styleable.TopBar_LeftTitleTextColor,0);

????????rightText??=?ta.getString(R.styleable.TopBar_RightTitle);
????????rightBackground?=?ta.getDrawable(R.styleable.TopBar_RightTitleBackground);
????????rightColor?=?ta.getColor(R.styleable.TopBar_RightTitleTextColor,0);

????????TitleText??=?ta.getString(R.styleable.TopBar_Title);
????????TitleSize?=?ta.getDimension(R.styleable.TopBar_TitleTextSize,0);
????????TitleColor?=?ta.getColor(R.styleable.TopBar_TitleTextColor,0);

????????ta.recycle();

????????LeftBtn?=?new?Button(context);
????????rightBtn?=?new?Button(context);
????????tvTitle?=?new?TextView(context);

????????LeftBtn.setText(LeftText);
????????LeftBtn.setBackground(leftBackground);
????????LeftBtn.setTextColor(LeftColor);

????????rightBtn.setText(rightText);
????????rightBtn.setBackground(rightBackground);
????????rightBtn.setTextColor(rightColor);

????????tvTitle.setText(TitleText);
????????tvTitle.setTextSize(TitleSize);
????????tvTitle.setTextColor(TitleColor);
????????tvTitle.setGravity(Gravity.CENTER);

????????setBackgroundColor(0xFFF59563);
????????
????????leftParams?=?new?LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,?ViewGroup.LayoutParams.WRAP_CONTENT);
????????leftParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT,TRUE);
????????
????????addView(LeftBtn,leftParams);

????????rightParams?=?new?LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,?ViewGroup.LayoutParams.WRAP_CONTENT);
????????rightParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,TRUE);

????????addView(rightBtn,rightParams);

????????TitleParmas?=?new?LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,?ViewGroup.LayoutParams.MATCH_PARENT);
????????TitleParmas.addRule(RelativeLayout.CENTER_IN_PARENT,TRUE);

????????addView(tvTitle,TitleParmas);

????}

5773c7a40001e87705000283.jpg

5773c7a500018bb705000442.jpg


正在回答

3 回答

如果出現(xiàn)命名空間找不到的問(wèn)題,一定要注意,declare 中聲明的name 一定要和建立的Java文件的名字一模一樣!

0 回復(fù) 有任何疑惑可以回復(fù)我~

@西瓜牛奶你的問(wèn)題解決沒(méi),我也遇到一樣的問(wèn)題了

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

西瓜牛奶 提問(wèn)者

我的解決了,是構(gòu)造方法的問(wèn)題,如果有自定義屬性的話,應(yīng)該用三個(gè)參數(shù)的構(gòu)造方法
2016-08-03 回復(fù) 有任何疑惑可以回復(fù)我~

把自定義的屬性在xml中都寫全就顯示出來(lái)了。還有要注意當(dāng)前model中的自定義屬性是否同其他定義的屬性重名(如果重名,會(huì)R報(bào)錯(cuò))。

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Android UI模板設(shè)計(jì)
  • 參與學(xué)習(xí)       76030    人
  • 解答問(wèn)題       233    個(gè)

快來(lái)學(xué)習(xí)如何在Android中自定義View,本次課程一定會(huì)讓你獲益匪淺

進(jìn)入課程

為什么xml里面顯示不出自定義的按鈕和TextView

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)