一开始:我是Android和Java编程的新手,但我在其他编程语言方面有很多经验,如C,C ++,Perl,PerlTk,OpenGL,Pascal,微控制器编程(C,汇编)等。 ..我做了一项研究,我尝试了很多东西,但没有任何帮助。
所以我想更改listview中的字体大小和字体颜色。 我找到了2个解决方案:
黑客风格。这是有效的,但是如果我修改我的风格而不是修改所有其他元素,那么从这种风格构建的是什么。所以没有,如果我选择这种方法,我仍然无法修改按下的列表视图而不是按下状态背景颜色。
自定义布局。我更喜欢这种方法,但是如果我引用布局,那么eclipse说:“无法解决,或者不是一个领域”
我的代码:
public class Btcall extends Activity
{
private ListView list;
final int REQUEST_ENABLE_BT = 1;
TextView kiirni;
TextView scanned;
View view2;
View view3;
Button connectbutton;
private ArrayAdapter<String> founddevices = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_btcall);
view2=(View) findViewById(R.id.view2);
view3=(View) findViewById(R.id.view3);
connectbutton=(Button) findViewById(R.id.button1);
kiirni=(TextView)findViewById(R.id.text1);
scanned=(TextView)findViewById(R.id.scanned);
list = (ListView) findViewById(R.id.list1);
}
public void irddki(View v)
{
BluetoothAdapter bluetooth = null;
BroadcastReceiver mReceiver = null;
bluetooth = BluetoothAdapter.getDefaultAdapter();
founddevices = null;
if(bluetooth != null)
{
String status;
if (bluetooth.isEnabled())
{
String mydeviceaddress = bluetooth.getAddress();
String mydevicename = bluetooth.getName();
status = mydevicename + " : " + mydeviceaddress;
Toast.makeText(this, status, Toast.LENGTH_LONG).show();
bluetooth.startDiscovery();
mReceiver = new BroadcastReceiver()
{
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action))
{
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
founddevices.add(device.getName() + "\n" + device.getAddress());
}
}
};
scanned.setVisibility(View.VISIBLE);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(470, 270, 0, 0);
connectbutton.setLayoutParams(lp);
connectbutton.setText("Scan again");
kiirni.setVisibility(View.GONE);
list.setBackgroundResource(R.color.Lightgrayy);
list.setVisibility(View.VISIBLE);
view2.setVisibility(View.VISIBLE);
view3.setVisibility(View.VISIBLE);
/*HERE IS THE PROBLEM--->*/
founddevices = new ArrayAdapter<String>(this, android.R.layout.mylist);
list = (ListView) findViewById(R.id.list1);
list.setAdapter(founddevices);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter);
}
else
{
if (!bluetooth.isEnabled())
{
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
}
}
}
public void close(View v)
{
moveTaskToBack(true);
}
}
我写了一个custum布局,我将它放在layouts文件夹中,它也在R文件夹中。
Eclipse还是看不到它......也许我必须导入一些东西?我确信这是一个菜鸟Q但我会很感激答案。
答案 0 :(得分:0)
尝试使用:
R.layout.mylist
而不是:
android.R.layout.mylist