package com.xys.multiplexedmodule;
public interface TopBarClickListener {
void leftBtnClick();
void rightBtnClick();
}
对我们自定义的模板控件,我们需要设定他的一些参数,在Values下新建attrs.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--declare-styleable:自定义属性的值 -->
<declare-styleable>
<attr format="string" />
<attr format="dimension" />
<attr format="color" />
<attr format="color" />
<attr format="string" />
<attr format="string" />
<attr format="color" />
<attr format="string" />
<attr format="string" />
</declare-styleable>
</resources>
现在我们就已经做好了一个模板,我们要如何使用他呢,很简单:
测试类:
package com.xys.multiplexedmodule;
import Android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast;
public class TestActivity extends Activity {
private MultipleTopBar topBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
topBar=(MultipleTopBar)findViewById(R.id.topBar);
topBar.setTopBarClickListener(new TopBarClickListener() {
@Override
public void rightBtnClick() {
// TODO Auto-generated method stub
Toast.makeText(TestActivity.this, "你点击的是右边的按钮", Toast.LENGTH_LONG).show();
}
@Override
public void leftBtnClick() {
// TODO Auto-generated method stub
Toast.makeText(TestActivity.this, "你点击的是左边的按钮", Toast.LENGTH_LONG).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}