一开始:我是 Android 和 Java 编程的新手,但我对其他编程语言如 C、C++、Perl、PerlTk、OpenGL、Pascal、微控制器编程(C、Assembly)等有很多经验......我进行了一项研究,我尝试了很多东西,但没有任何帮助。
所以我想在我的列表视图中更改字体大小和字体颜色。我找到了2个解决方案:
破解风格。这是可行的,但是如果我修改我的样式而不是修改所有其他元素,那么从这种样式构建的是什么。所以不,如果我仍然选择这种方法,我将无法修改 listview 按下和未按下状态背景颜色。
自定义布局。我更喜欢这种方法,但是如果我参考布局,日食会说:“无法解析,或者不是字段”
我的代码:
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);
}
}
我写了一个自定义布局,我把它放在 layouts 文件夹中,它也在 R 文件夹中。
Eclipse 仍然看不到它......也许我必须导入一些东西?我确信这是一个菜鸟 Q,但我会很感激答案。