标签: android-xml

ActionBarSherlock:更改homeAsUpIndicator不起作用

我想通过将以下样式应用到我的活动来更改向上图标,但它不起作用,但我仍然得到默认的黑色"<"图标.

任何人都可以找到这里缺少的东西吗?

<style name="AppTheme.ActionBar" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarStyle">@style/actionBarStyle</item>
    <item name="android:actionBarStyle">@style/actionBarStyle</item>
</style>

<style name="actionBarStyle" parent="@style/Widget.Sherlock.Light.ActionBar.Solid">
    <item name="android:background">@drawable/header_bar</item>
    <item name="background">@drawable/header_bar</item>

    <item name="android:homeAsUpIndicator">@drawable/up_indicator</item>
    <item name="homeAsUpIndicator">@drawable/up_indicator</item>
    <item name="android:displayOptions">homeAsUp|showHome</item>
    <item name="displayOptions">homeAsUp|showHome</item>

</style>
Run Code Online (Sandbox Code Playgroud)

android android-xml actionbarsherlock android-actionbar

4
推荐指数
1
解决办法
9614
查看次数

Android:如何使用屏幕尺寸缩放布局

考虑以下布局(从此处拉出):

在此处输入图片说明

我想了解使此布局随屏幕尺寸缩放的原理。对于正方形,自定义onMeasure函数可以很好地工作:

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
Run Code Online (Sandbox Code Playgroud)

下面的自定义Togglebuttons和Imagebuttons的宽度和高度应缩放以填充屏幕的其余部分,减去layout_margins,其中的文本和图像应缩放以填充按钮,以减少填充。外边缘也应缩放。

我的第一个想法是使用相对布局来放置按钮,并使用layout_margin / padding属性创建边距。但是,相对布局和layout_margin / padding需要固定的像素值,因此它们不可缩放。

然后,我想到了使用带有layout_weights的嵌套线性布局来定位按钮,并使用占位符视图来创建边距。尽管这些技术具有可伸缩性,但它们不适用于按钮,因为按钮具有许多需要固定像素值的属性(文本大小,图像大小,拐角半径等)。例如,此限制意味着以下xml:

<ToggleButton 
    android:layout_weight="1"
    style="@style/myButton"
    [...] />
<View 
    android:layout_weight="1"/>
<ImageButton 
    android:layout_weight="1"
    style="@style/myButton"
    [...] />
Run Code Online (Sandbox Code Playgroud)

不一定会使两个按钮以及它们之间的间距都相同。这完全取决于按钮的文本大小,图像大小等。

我看了这个问题,但是我觉得应该为这样一个简单的问题提供一个更简单的解决方案,即不需要使用过多的非XML。

android android-layout android-xml

4
推荐指数
2
解决办法
1万
查看次数

在RelativeLayout中使用重力右对齐TextView

我试图让editText坐在我的布局的右边缘,左边有一个按钮,如下所示:

  <RelativeLayout
    android:id="@+id/FindClientLayout"
    android:layout_width="@dimen/third_width"
    android:layout_height="@dimen/half_height"
    android:layout_alignParentLeft="false"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="false"
    android:layout_below="@id/HeaderLayout"
    android:layout_margin="@dimen/fragment_separation"
    android:layout_toRightOf="@id/scrollViewRecommend"
    android:background="@drawable/login_border" >

    <TextView
        android:id="@+id/textViewFindClient"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="@string/find_client"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/Black" />

    <EditText 
        android:id="@+id/editTextClient"
        android:layout_width="@dimen/input_text_width"
        android:layout_height="wrap_content"
        android:gravity="center_vertical|right"
        android:inputType="text"/>
    <Spinner
        android:id="@+id/spinnerClientList"
        android:layout_width="@dimen/input_text_width"
        android:layout_height="wrap_content"
        android:layout_below="@id/editTextClient"/>

    <Button
        android:id="@+id/buttonDoFind"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:layout_toLeftOf="@id/editTextClient"
        android:text="@string/find" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

该按钮是不可见的,结果如下所示:

布局

我假设按钮是不可见的,因为editText左对齐并覆盖它或将其推出布局框架.为什么editText和微调器左对齐而不是右对齐?另外,为什么editText没有垂直居中?

android android-layout android-xml

4
推荐指数
2
解决办法
1万
查看次数

如何绘制自定义背景

我必须设计一个三角形并在其中显示一些角度为45的文本,我必须将文本视图放在三角形的边界之外以显示其他文本.它就像一面旗帜.但是,当我使用相对布局并放置三角形背景时,它仍然充当矩形,遮挡了我的文本视图.以下是我使用的代码:

<RelativeLayout
        android:id="@+id/relative"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/image_sticker" >

        <com.example.AngledTextView
            android:id="@+id/textViewx"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:rotation="52"
            android:textColor="#FFFFFF" />
    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我的AngledTextView类:

public class AngledTextView extends TextView  {  

    private int mWidth;
    private int mHeight;


    public AngledTextView(Context context, AttributeSet attrs)  {  
        super(context, attrs);  

    }  



    @Override  
    protected void onDraw(Canvas canvas) {  
        canvas.save();  
        /*Paint textPaint = new Paint(); 
        int xPos = (canvas.getWidth() / 2);
        int yPos = (int) ((canvas.getHeight() / 2) - ((textPaint.descent() + textPaint.ascent()) / 2)) ; 

            canvas.rotate(45, xPos,yPos);   */

        super.onDraw(canvas);  
        canvas.restore();  
    }  
} …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml

4
推荐指数
1
解决办法
2628
查看次数

Android:如何调整图片大小以填充父级?

我正在开发显示图像的应用程序,我需要创建一个以1:1宽高比显示大图像的视图.

首先,我有一些72x72分辨率的缩略图.我已经把他们在ImageView,但即使我添加参数android:width="fill_parent"android:height="wrap_content",图像也不会不的大小ImageView,但只在中间居中.

我尝试添加参数android:scaleType="centerCrop",水平调整图像大小,但高度保持不变.

我怎么能设置我的ImageView所有设备在所有设备上的宽度与父视图一样,它也应该是高度.

我可以以编程方式执行此操作,但我需要能够以XML格式执行此操作.

我的XML文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    // The ImageView I am talking about above
    <ImageView
        android:id="@+id/invitation_imageview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="1dp"
        android:scaleType="centerCrop"
        android:src="@drawable/face_woman_smile" />

    <ImageView
        android:id="@+id/invitation_avatar_view_1"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:src="@drawable/face_woman_smile"
        android:scaleType="center"
        android:layout_margin="1dp" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android image android-layout android-xml scaletype

4
推荐指数
1
解决办法
5643
查看次数

通过代码使文本发光.(机器人)

我想知道如何让我的文字在android中发光,我知道如何通过xml做一些属性,如下所示:

android:shadowColor="#6A8B00"
android:shadowDx="3"
android:shadowDy="3"
android:shadowRadius="10"
android:text="@string/glowText"
android:textColor="#E15529"
android:textSize="30sp"
Run Code Online (Sandbox Code Playgroud)

但我想通过代码来做,然后我可以更好地控制,并在不同情况下或多或少地发光.也许像view.setGlow?

感谢您的任何帮助.

android textview glow android-xml

4
推荐指数
1
解决办法
1474
查看次数

从右到左的菜单项Android

我有一个幻灯片菜单作为图片之一.我需要将其项目标题从右到左对齐,如幻灯片二.我尝试了引力=对,但没有奏效.

这是我的代码:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:gravity="end"
    android:layout_gravity="end">

    <group android:checkableBehavior="single"
        android:layout_gravity="end"
        android:gravity="end">

        <item
            android:id="@+id/nav_1"
            android:icon="@drawable/ic_keyboard_arrow_left_24dp"
            android:gravity="end"
            android:layout_gravity="end"
            android:title="???? ??? ?? ??? ????"/>

</menu>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

所需的菜单将是:

在此输入图像描述

android android-layout android-xml

4
推荐指数
1
解决办法
8942
查看次数

致命异常:java.lang.SecurityException:缺少插入标记的权限

我是Android开发的新手,在Play商店发布之后,我面临一些设备的异常.这对我来说完全不为人知.此异常强制停止/崩溃我的应用程序.

记录完整的堆栈跟踪:

Exception java.lang.SecurityException: Missing permission to insert badges
android.os.Parcel.readException (Parcel.java:1553)
android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:185)
android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:137)
android.content.ContentProviderProxy.insert (ContentProviderProxy.java:476)
android.content.ContentResolver.insert (ContentResolver.java:1213)
android.content.AsyncQueryHandler$WorkerHandler.handleMessage (AsyncQueryHandler.java:96)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:211)
android.os.HandlerThread.run (HandlerThread.java:61)
Run Code Online (Sandbox Code Playgroud)

如上所述,例外剂量不包含与我的申请相关的任何代码部分,而且我也没有找到任何满意的上述问题的解决方案.

编辑: 我正在使用外部库(SDK)进行推送通知,添加我的应用程序开始在Play商店显示11个新权限"必需权限"部分,当我要更新我的应用程序

其中一些权限是:

    com.htc.launcher.permission.READ_SETTINGS
    com.htc.launcher.permission.UPDATE_SHORTCUT
    com.huawei.android.launcher.permission.CHANGE_BADGE
    com.huawei.android.launcher.permission.READ_SETTINGS
    com.huawei.launcher.permission.WRITE_SETTINGS
    com.sec.android.provider.badge.permission.READ
    com.sec.android.provider.badge.permission.WRITE
    com.sonyericsson.home.permission.BROADCAST_BADGE
    com.sonymobile.home.permission.PROVIDE_INSERT_BADGE
Run Code Online (Sandbox Code Playgroud)

我没有在我自己的清单文件中添加这些权限,因此我通过在应用程序标记中添加以下代码行来修改我的'AndroidManifest'文件:

<application
     <--some code-->
    tools:replace="android:icon, android:allowBackup"
    >
Run Code Online (Sandbox Code Playgroud)

并使用SDK的.jar文件而不是编译它

编译'com.abc.xyz:3.+@aar'//为android studio(build.gradle)建议

应用上述过程后,这些权限将被删除,我上传我的应用程序.

只有我在我的新版应用程序中执行了这些操作.我最近也看了那个库项目,它包含一个文件夹'shortcutbadger',里面包含一些子文件夹和.class文件

是由于上述变化,我开始收到该例外?请解释/帮助!

android android-manifest android-xml android-permissions android-securityexception

4
推荐指数
1
解决办法
4030
查看次数

RecyclerView在ScrollView上不是trully wrap_content

我有一个ScrollView,包含垂直LinearLayout.的地方这是一个地方,我添加了一些名为"Section"的视图."Section" LinearLayout,包含一个TextView和`RecyclerView.

<ScrollView
    android:id="@+id/main_scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/sections_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" />
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

部分:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:textSize="@dimen/activity_starred_title_textsize" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

问题是有时RecyclerView并非真正的问题wrap_content.因此,它会产生两种类型的问题(取决于我尝试使用的解决方案类型).

  1. 它可以是不可滚动的(因此它匹配屏幕高度,我无法向下滚动以查看其中的其余项目).

  2. 它可以滚动嵌套.

最初的问题是它有嵌套滚动.所以我想要RecyclerViews简单的垂直LinearLayouts,唯一必须具有滚动效果的是rootScrollView.

我试过做什么?

  1. 扩展GridLayoutManager和覆盖canScrollVertically().方法:

    public boolean canScrollVertically(){return false; }

  2. 扩展RecyclerView类和覆盖

    @Override public boolean onInterceptTouchEvent(MotionEvent event){return false; }

    @Override public boolean onTouchEvent(MotionEvent event){return false; } …

android android-layout android-xml android-recyclerview

4
推荐指数
1
解决办法
2476
查看次数

在BottomSheetDialogFragment内部添加/替换片段

此代码:在其中我要添加片段的地方打开bottomSheetDialogFragment。

我想在bottomsheetDialogFragment中添加多个片段,但是会抛出

java.lang.IllegalArgumentException:找不到ID为0x7f0a01cb的视图

class AddNotesBottomSheetDialog : BottomSheetDialogFragment() {

private lateinit var bottomSheetDialog: BottomSheetDialog
private lateinit var bottomSheetBehavior: BottomSheetBehavior<View>

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    Log.v(LOG_TAG, "-> onCreateDialog")

    bottomSheetDialog = BottomSheetDialog(context!!)

    var view = View.inflate(context, R.layout.bottom_sheet_notes, null)
    bindViews(view)
    bottomSheetDialog.setContentView(view)
    bottomSheetBehavior = BottomSheetBehavior.from(view.parent as View)
    bottomSheetBehavior.isHideable = false
    bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED

    return bottomSheetDialog
}

private fun bindViews(view: View) {
    loadAddNotesFragments()

}

override fun onStart() {
    super.onStart()
    Log.v(LOG_TAG, "-> onStart")

    bottomSheetBehavior.isHideable = false
    bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
    if (!visible)
        dialog.hide()
}


fun show(fragmentManager: FragmentManager) …
Run Code Online (Sandbox Code Playgroud)

android android-xml bottom-sheet

4
推荐指数
1
解决办法
1877
查看次数