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

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

不能識(shí)別自定義控件中的屬性,自定義控件的三個(gè)子控件也不能正常顯示?

package com.jia.mytopbar;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
* Created by Administrator on 2016/8/29.
*/
public class TopBar extends RelativeLayout {

? ?private Button leftButton,rightButton;
? ?private TextView tvTitle;
? ?
? ?private int leftTextColor;
? ?private Drawable leftBackground;
? ?private String leftText;
? ?private int rightTextColor;
? ?private Drawable rightBackground;
? ?private String rightText;
? ?private float centerTitleTextSize;
? ?private int centerTitleTextColor;
? ?private String centerTitle;

? ?private LayoutParams leftParams,rightParams,centerTitleParams;

? ?//重寫構(gòu)造方法
? ?public TopBar(Context context, AttributeSet attrs) {
? ? ? ?super(context, attrs);
? ? ? ?//取值
? ? ? ?TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.TopBar);

? ? ? ?leftTextColor = ta.getColor(R.styleable.TopBar_leftTextColor,0);
? ? ? ?leftBackground = ta.getDrawable(R.styleable.TopBar_leftBackground);
? ? ? ?leftText = ta.getString(R.styleable.TopBar_leftText);

? ? ? ?rightTextColor = ta.getColor(R.styleable.TopBar_rightTextColor,0);
? ? ? ?rightBackground = ta.getDrawable(R.styleable.TopBar_rightBackground);
? ? ? ?rightText = ta.getString(R.styleable.TopBar_rightText);

? ? ? ?centerTitleTextSize = ta.getDimension(R.styleable.TopBar_centerTitleTextSize, 0);
? ? ? ?centerTitleTextColor = ta.getColor(R.styleable.TopBar_centerTitleTextColor, 0);
? ? ? ?centerTitle = ta.getString(R.styleable.TopBar_centerTitle);

? ? ? ?ta.recycle();
? ? ? ?//組合模式,定義已有組件,拼合
? ? ? ?leftButton = new Button(context);
? ? ? ?rightButton = new Button(context);
? ? ? ?tvTitle = new TextView(context);
? ? ? ?
? ? ? ?leftButton.setTextColor(leftTextColor);
? ? ? ?leftButton.setBackground(leftBackground);
? ? ? ?leftButton.setText(leftText);

? ? ? ?rightButton.setTextColor(rightTextColor);
? ? ? ?rightButton.setBackground(rightBackground);
? ? ? ?rightButton.setText(rightText);

? ? ? ?tvTitle.setText(centerTitle);
? ? ? ?tvTitle.setTextColor(centerTitleTextColor);
? ? ? ?tvTitle.setTextSize(centerTitleTextSize);
? ? ? ?tvTitle.setGravity(Gravity.CENTER);

? ? ? ?setBackgroundColor(0xFFF59563);

? ? ? ?//把一個(gè)控件添加到ViewGroup
? ? ? ?leftParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT);
? ? ? ?leftParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT,TRUE);
? ? ? ?addView(leftButton,leftParams);

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

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

? ?}
}

<?xml?version="1.0"?encoding="utf-8"?>
<RelativeLayout?xmlns:android="http://schemas.android.com/apk/res/android"
????xmlns:custom="http://schemas.android.com/apk/res-auto"
????xmlns:tools="http://schemas.android.com/tools"
????android:layout_width="match_parent"
????android:layout_height="match_parent"
????android:paddingBottom="@dimen/activity_vertical_margin"
????android:paddingLeft="@dimen/activity_horizontal_margin"
????android:paddingRight="@dimen/activity_horizontal_margin"
????android:paddingTop="@dimen/activity_vertical_margin"
????tools:context="com.jia.mytopbar.MainActivity">

????<com.jia.mytopbar.TopBar

????????android:id="@+id/topbar"
????????android:layout_width="match_parent"
????????android:layout_height="40dp">
????????custom:leftBackground="#ff08dd55"
????????custom:leftText="Back"
????????custom:leftTextColor="#ffffff"
????????custom:rightBackground="#ff08dd55"
????????custom:rightText="Back"
????????custom:rightTextColor="#ffffff"
????????custom:centerTitle="自定義標(biāo)題"
????????custom:centerTitleTextColor="#123456"
????????custom:titleTextSize="16sp"
????</com.jia.mytopbar.TopBar>
</RelativeLayout>

http://img1.sycdn.imooc.com//57c6da710001b9d111920676.jpg


<?xml version="1.0" encoding="utf-8"?>
<resources>
? ?<declare-styleable name="TopBar">
? ? ? ?<attr name="centerTitle" format="string" />
? ? ? ?<attr name="centerTitleTextSize" format="dimension" />
? ? ? ?<attr name="centerTitleTextColor" format="color" />
? ? ? ?<attr name="leftTextColor" format="color" />
? ? ? ?<attr name="leftBackground" format="reference|color" />
? ? ? ?<attr name="leftText" format="string" />
? ? ? ?<attr name="rightTextColor" format="color" />
? ? ? ?<attr name="rightBackground" format="reference|color" />
? ? ? ?<attr name="rightText" format="string" />
? ?</declare-styleable>
</resources>


正在回答

3 回答

leftBackground和rightBackground是drawable類型,你這塊直接給了int類型。你可以在drawable文件夾中放置圖片或者定義drawable資源文件來(lái)實(shí)現(xiàn)

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

請(qǐng)問(wèn),你的問(wèn)題解決了么?我也是這個(gè)問(wèn)題

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

流沙009 提問(wèn)者

還沒(méi)解決,你如果解決共享一下
2016-09-22 回復(fù) 有任何疑惑可以回復(fù)我~

xml文件中對(duì)于安卓系統(tǒng)屬性的引用你沒(méi)寫 xmlns:android=" ?,這后面有一串引用地址的,不寫的話系統(tǒng)誤以為是xmlns:custom="http://schemas.android.com/apk/res-auto"這個(gè)地址

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)入課程

不能識(shí)別自定義控件中的屬性,自定義控件的三個(gè)子控件也不能正常顯示?

我要回答 關(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)