亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

兩邊的button不能點擊,button的text屬性和background屬性設置后都能顯示,但是點擊上面的文字卻沒任何反應,就好像變成了textview一樣。

package com.example.test;


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;


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 titleTextsize;

private int titleTextcolor;

private String ?title;

private LayoutParams leftparams, rightparams, titleparams;

public Topbar(Context context, AttributeSet attrs) {

super(context, attrs);

// TODO Auto-generated constructor stub

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);

? ?

titleTextsize=ta.getDimension(R.styleable.Topbar_titleTextSize,0);

titleTextcolor=ta.getColor(R.styleable.Topbar_titleTextColor,0);

title=ta.getString(R.styleable.Topbar_title);

?

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.setTextColor(titleTextcolor);

tvTitle.setTextSize(titleTextsize);

tvTitle.setText(title);

tvTitle.setGravity(Gravity.CENTER);

?

setBackgroundColor(0xFFF59563);

?

leftparams=new LayoutParams(ViewGroup.LayoutParams.

WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

leftparams.addRule(RelativeLayout.ALIGN_PARENT_LEFT,TRUE);

addView(leftButton, leftparams);

?

rightparams=new LayoutParams(ViewGroup.LayoutParams.

WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

rightparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,TRUE);

addView(rightButton, rightparams);

?

titleparams=new LayoutParams(ViewGroup.LayoutParams.

WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

titleparams.addRule(RelativeLayout.CENTER_IN_PARENT,TRUE);

addView(tvTitle, titleparams);

?

}


}


正在回答

2 回答

同問,請問解決了嗎

0 回復 有任何疑惑可以回復我~

button沒有設置click事件

0 回復 有任何疑惑可以回復我~
#1

zdhcristy

設置了事件之后點擊Button有效,但是沒有點擊效果怎么破?
2016-05-04 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Android UI模板設計
  • 參與學習       76032    人
  • 解答問題       233    個

快來學習如何在Android中自定義View,本次課程一定會讓你獲益匪淺

進入課程

兩邊的button不能點擊,button的text屬性和background屬性設置后都能顯示,但是點擊上面的文字卻沒任何反應,就好像變成了textview一樣。

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號