在更新到Android Studio 3并使用最新的SDK和构建工具后,有一项功能可以将字体添加到fonts
资源下的文件夹中,并直接在xml或java中使用它.我在我的主题中使用此代码在styles.xml
我的整个应用程序中应用主题
<item name="android:fontFamily">@font/iransansfont</item>
Run Code Online (Sandbox Code Playgroud)
它正在工作Button
,TextView
几乎除了CheckBox
和Switch
小工具之外的一切.我甚至尝试过fontFamily
我的CheckBox
s和Switch
s但它也没有用.我该如何解决?
我正在使用compileSdk
和targetSdk
版本27,在最后一个版本中,我为我的项目使用了新的字体资源功能但是在一天之后我为这行代码遇到了3次崩溃
Typeface typeface = ResourcesCompat.getFont(this, R.font.my_font);
Run Code Online (Sandbox Code Playgroud)
并且崩溃报告说它是因为android.content.res.Resources$NotFoundException
和无法检索字体资源.所有3次崩溃都发生在Android版本的用户身上5.1.1
.这是支持库中的错误还是我做错了什么?
在我onBindViewHolder
的RecyclerView.Adapter<SearchAdapter.ViewHolder>
用户点击cardview
按钮时,我可以看到.但是当我滚动recyclerview时,其他一些项目按钮也显示为可见.为什么会这样?
这是我的代码:
@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
viewHolder.card.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (viewHolder.content_layout.getVisibility() == View.VISIBLE) {
viewHolder.content_layout.setVisibility(View.GONE);
viewHolder.address.setMaxLines(2);
viewHolder.attribute.setMaxLines(2);
} else {
viewHolder.content_layout.setVisibility(View.VISIBLE);
viewHolder.address.setMaxLines(8);
viewHolder.attribute.setMaxLines(8);
}
}
});
...
}
Run Code Online (Sandbox Code Playgroud) 这是我实现谷歌地图的代码,并且CLLocationManager
:
class MapViewController: UIViewController {
@IBOutlet weak var MapView: GMSMapView!
var locationmanager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationmanager.delegate = self
locationmanager.requestWhenInUseAuthorization()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
extension MapViewController: CLLocationManagerDelegate {
private func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
print("didChangeAuthorizationStatus")
if status == .authorizedWhenInUse {
locationmanager.startUpdatingLocation()
MapView.isMyLocationEnabled = true
MapView.settings.myLocationButton = true
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("didUpdateLocations")
if let location = locations.first {
MapView.camera = GMSCameraPosition(target: location.coordinate, zoom: …
Run Code Online (Sandbox Code Playgroud) 嘿,在用户点击标记应用程序崩溃的地图活动中,我在logcat中得到这个,这不是由我的应用程序中的类引起的,我无法找到为什么我得到它
E/AndroidRuntime: FATAL EXCEPTION: main
Process: ir.aftabeshafa.shafadoc, PID: 24320 java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
at android.util.PathParser$PathDataNode.addCommand(PathParser.java:380)
at android.util.PathParser$PathDataNode.nodesToPath(PathParser.java:260)
at android.graphics.drawable.VectorDrawable$VPath.toPath(VectorDrawable.java:1265)
at android.graphics.drawable.VectorDrawable$VPathRenderer.drawPath(VectorDrawable.java:950)
at android.graphics.drawable.VectorDrawable$VPathRenderer.drawGroupTree(VectorDrawable.java:931)
at android.graphics.drawable.VectorDrawable$VPathRenderer.draw(VectorDrawable.java:938)
at android.graphics.drawable.VectorDrawable$VectorDrawableState.updateCachedBitmap(VectorDrawable.java:705)
at android.graphics.drawable.VectorDrawable.draw(VectorDrawable.java:280)
at android.widget.ImageView.onDraw(ImageView.java:1148)
at android.view.View.draw(View.java:15171)
at android.view.View.updateDisplayListIfDirty(View.java:14096)
at android.view.View.getDisplayList(View.java:14119)
at android.view.View.draw(View.java:14895)
at android.view.ViewGroup.drawChild(ViewGroup.java:3407)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3201)
at android.view.View.draw(View.java:15174)
at android.view.View.updateDisplayListIfDirty(View.java:14096)
at android.view.View.getDisplayList(View.java:14119)
at android.view.View.draw(View.java:14895)
at android.view.ViewGroup.drawChild(ViewGroup.java:3407)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3201)
at android.view.View.updateDisplayListIfDirty(View.java:14091)
at android.view.View.getDisplayList(View.java:14119)
at android.view.View.draw(View.java:14895)
at android.view.ViewGroup.drawChild(ViewGroup.java:3407)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3201)
at android.view.View.draw(View.java:15174)
at android.widget.FrameLayout.draw(FrameLayout.java:592)
at android.view.View.updateDisplayListIfDirty(View.java:14096)
at android.view.View.getDisplayList(View.java:14119)
at android.view.View.draw(View.java:14895)
at android.view.ViewGroup.drawChild(ViewGroup.java:3407)
at android.support.design.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1195)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3201) …
Run Code Online (Sandbox Code Playgroud) 我正在使用Swift创建应用程序UI的一部分,我面临的问题是我有UIStackView
3个子视图:2个UILabel和一个UIImageView.这是我的第一个代码
let switchview = UISwitch()
let nodelableview = UILabel()
nodelableview.textAlignment = NSTextAlignment.right
nodelableview.numberOfLines = 0
nodelableview.text = nodes[i].type + " " + nodes[i].node_name
let statLabel = UILabel()
statLabel.textAlignment = NSTextAlignment.left
statLabel.text = nodes[i].stat
let stack = UIStackView()
stack.axis = .horizontal
stack.spacing = 16
stack.addArrangedSubview(statLabel)
stack.addArrangedSubview(nodelableview)
stack.addArrangedSubview(switchview)
cell.nodesView.addArrangedSubview(stack)
Run Code Online (Sandbox Code Playgroud)
这段代码的问题在于,当nodelabelview
文本较长时,UIStackView不会扩展为2行或更多行的空间.所以我将对齐设置为.center
,结果就是这里
剩下空的空间,但第一个是空闲的空间UILabel
.如何强制第二个UILabel
使用可用空格?
我在android studio中有一个带有自定义列表视图的项目.我的自定义列表视图包含2textbox和一个开关和图像按钮,但我无法找到如何在listadapter类中为它们设置onclicklistener或其他监听器
这是我的listadapter:
public class listadapter extends ArrayAdapter {
Context context_;
int resource_;
ArrayList<reminders> objects_;
boolean bool;
DBAdapter db;
public listadapter(Context context, int resource, ArrayList<reminders> objects) {
super(context, resource, objects);
context_ = context;
resource_ = resource;
objects_ = objects;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context_.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View ViewRow = inflater.inflate(R.layout.reminders_list_layout, parent, false);
TextView nametxt, addresstxt;
Switch sw;
ImageView imgview;
nametxt = (TextView) ViewRow.findViewById(R.id.remindername);
addresstxt = (TextView) ViewRow.findViewById(R.id.reminderaddress);
sw = (Switch) ViewRow.findViewById(R.id.remindersw);
imgview …
Run Code Online (Sandbox Code Playgroud) 我想要我的对话框活动的透明导航栏和状态栏,我的风格有以下代码:
<style name="AppTheme.Dialog" parent="Theme.AppCompat.Dialog">
<item name="colorAccent">@color/gray</item>
<item name="windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这在java中:
public class FilterActivity extends AppCompatActivity {
FloatingActionButton fab;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
setContentView(R.layout.filter_activity);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
fab = (FloatingActionButton) findViewById(R.id.fab_filter_close);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
我的对话活动是全屏的,背景透明,但导航栏和状态栏是黑色的。我能做什么?
我想检测我edittext
是否有英文字符并通知用户更改它,因为我只想要名字和姓氏的波斯字符.我怎样才能过滤edittext
接受波斯语字符或检测英文字符并显示错误?
在故事板中我有一个UIPageViewController
,这是我的代码
class ReservedTimesViewController: UIPageViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
extension ReservedTimesViewController: UIPageViewControllerDataSource {
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ReservedTimesTableViewController")
print(controller)
return controller
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ReservedTimesTableViewController")
print(controller)
return controller
}
Run Code Online (Sandbox Code Playgroud)
这是我的ReservedTimesTableViewController
故事板
但我遇到黑屏。为什么它不能正常工作?