Android Studio 开发,找不到android.support.v7.app 问题

Android Studio 开发,找不到android.support.v7.app 问题

程序中有:

import android.support.v7.app.AppCompatActivity;

但是v7呈现红色报错,鼠标移到v7处,显示cannot resolve symbol ‘v7’
在下方 Build 栏中有提示

找不到软件包android.support.v7.app

解决办法:
File -> Project Structure
点击后出现 Project Structure 窗口。

然后选择左边竖栏的 app,
选择app后,在右边选择 Dependencies 页面
点击最右边的“+”号,选择第一项 Library dependency

具体该选择添加哪些?,= =,无奈的选择把所有包含‘v7’的项目全部添加了。

添加完成后,程序可以通过编译。

安卓Android java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

首先得知道Android的四大组件:活动(Activity)服务(Service)广播接收器(BroadcastReceiver)和内容提示器(Content Provider),其中活动是所有Android应用程序的门面,凡是在应用中看到的东西,都是放在活动中的。

查看报错信息如下:

起因:

想设置一个对话框式的活动,在AndroidMainfest.xml的<activity>标签的配置如下:

<activity android:name=”.DialogActivity”

android:theme=”@android:style/Theme.Dialog”/>

原因:

从错误提示中提到Theme.AppCompat theme,因为我们的activity一定是继承了兼容包中的类,

AndroidStudio帮我们创建的activity继承了ActionBarActivity,它来自android.support.v7.app.ActionBarActivity。

所以就要使用与其配合的AppCompat的theme才行。

解决方法有两种:

1: 将DialogActivity 改为直接继承Activity

2: 根据提示来使用AppCompat的theme

<activity android:name=”.DialogActivity”

android:theme=”@style/Theme.AppCompat.Dialog” />

重新运行,出现了理想的对话框式的活动。

问题不大,仅仅是一个小小的问题,但是重要的是分析问题和解决问题的过程,小问题解决了,以后遇到的大问题就可以分解成小问题,然后逐个解决。

 

能用Android Studio来学习JAVA吗

能用Android Studio来学习JAVA吗

可以,不过在创建了Android工程后,需要在里面创建一个Module,然后创建JAVA类,运行的话自己加一个main方法就可以了。

其他:

想学习java做android开发,直接用android studio可以么?

OS X 系统,翻墙intellij idea还是没配置好,但Android studio可以用了,可以直接用这个软件学java语言么,有c语言基础

 

Mysql按指定顺序排序的两种写法

SELECT `ID` FROM wp_posts WHERE `ID` in (1,2,3,4,5) ORDER BY FIELD(`ID`,5,4,3,1,2); // 纯数字字段不用处理引号,比较好拼接
SELECT `ID` FROM wp_posts WHERE `ID` in (1,2,3,4,5) ORDER BY FIND_IN_SET(`post_title`,'A,B,C,D,E'); // 一个引号全包住,搞定字符值字段
 
-- 注意:第一个参数不能是字符串,否则不起作用
-- 性能差异
SELECT id FROM cbd_hots WHERE id in (155,154) ORDER BY FIELD(`id`,154,155); // 纯数字字段不用处理引号,比较好拼接

亲测有效!

针对tp5中的这样的写法[orderRaw 代替order  ] 请使用orderRaw方法替代order

有业务需求如下:

select * from table where id IN (3,6,9,1,2,5,8,7) order by field(id,3,6,9,1,2,5,8,7);
但是也可以写成这样

->order("field(id,3,6,9,1,2,5,8,7)")
但是官方文档说了,当你的order排序中使用了SQL函数的时候,请使用orderRaw方法替代order 。

实践有效:

return Db::connect(config('database.sqla'))->name("hots")->where("id in (".$hots_ids.")")->orderRaw("field(id,".$hots_ids.")")->select();

 

 

SQL用了Union后的排序问题

有小伙伴反映:

最近使用SQL语句进行UNION查询,惊奇的发现:SQL没问题,UNION查询也没问题,都可以得到想要的结果,可是在对结果进行排序的时候,却出问题了。

 

SELECT a.id,a.username,a.mobile,a.time,a.leader,a.time
FROM (SELECT `id`,`username`,`mobile`,`time`,id AS leader 
	FROM `grouporder_leader` WHERE `courseid` = 21 AND `merchid` = 23 AND `status` = 1 
	UNION ALL 
	SELECT leadorderid,username,mobile,time,null 
	FROM `grouporder_partner` WHERE courseid=21 and status=1 and merchid=23
) AS a 
ORDER BY a.time DESC

注意事项:

1、必须声明临时表;

2、必须使用别名

js关闭浏览器的tab页(兼容)

由于在脚本中使用了 window.close(), 当前非弹出窗口在最新版本的chrome和firefox里总是不能关闭,而在 IE中是可以关闭的 。

      在console中弹出提示”Scripts may close only the windows that were opened by it” (脚本只能关闭它所打开的窗口),[如下图所示] , 不明白是什么原因。

首先,什么是非弹出窗口呢?

      非弹出窗口,即是指(opener=null 及 非window.open()打开的窗口,比如URL直接输入的浏览器窗体, 或由其它程序调用产生的浏览器窗口)。

其次,window.close() 怎么理解呢?

 

由 https://developer.mozilla.org/en-US/docs/Web/API/window.close 可知:

Closes the current window, or the window on which it was called.
When this method is called, the referenced window is closed.

This method is only allowed to be called for windows that were opened by a script using thewindow.open() method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.

Examples

Closing a window opened with window.open()

This example demonstrates how to use this method to close a window opened by script callingwindow.open().

<script type="text/javascript">
//Global var to store a reference to the opened window
var openedWindow;

function openWindow()
{
  openedWindow = window.open('moreinfo.htm');
}

function closeOpenedWindow()
{
  openedWindow.close();
}
</script>

Closing the current window

When you call the window object’s close() method directly, rather than calling close() on a windowinstance, the browser will close the frontmost window, whether your script created that window or not.

<script type="text/javascript">
function closeCurrentWindow()
{
  window.close();
}
</script>

在某些实际应用中,window.close() and self.close() 是不能关闭非弹出窗口(opener=null及非window.open()打开的窗口)。

方案一【推荐,亲身测试有效!!】:

function closeWindows() {
         var browserName = navigator.appName;
         var browserVer = parseInt(navigator.appVersion);
         //alert(browserName + " : "+browserVer);

         //document.getElementById("flashContent").innerHTML = "<br>&nbsp;<font face='Arial' color='blue' size='2'><b> You have been logged out of the Game. Please Close Your Browser Window.</b></font>";

         if(browserName == "Microsoft Internet Explorer"){
             var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;  
             if (ie7)
             {  
               //This method is required to close a window without any prompt for IE7 & greater versions.
               window.open('','_parent','');
               window.close();
             }
            else
             {
               //This method is required to close a window without any prompt for IE6
               this.focus();
               self.opener = this;
               self.close();
             }
        }else{  
            //For NON-IE Browsers except Firefox which doesnt support Auto Close
            try{
                this.focus();
                self.opener = this;
                self.close();
            }
            catch(e){

            }

            try{
                window.open('','_self','');
                window.close();
            }
            catch(e){

            }
        }
    }

方案二:

<script type="text/javascript">
function closeWP() {
 var Browser = navigator.appName;
 var indexB = Browser.indexOf('Explorer');

 if (indexB > 0) {
    var indexV = navigator.userAgent.indexOf('MSIE') + 5;
    var Version = navigator.userAgent.substring(indexV, indexV + 1);

    if (Version >= 7) {
        window.open('', '_self', '');
        window.close();
    }
    else if (Version == 6) {
        window.opener = null;
        window.close();
    }
    else {
        window.opener = '';
        window.close();
    }

 }
else {
    window.close();
 }
}
</script>

参考:https://www.cnblogs.com/exe19/p/5546719.html

 

空链接是使用javascript:void(0)还是使用#none

通过微信推送链接。在ios系统中(android显示正常),微信内页打开链接后,点击页面的一个按钮,页面被重新加载了,这时才可以对页面进行其它操作。

原因:a标签的引起的

<a href="#none" class="btn" id="btn"></a>

href=“#none” 这是本来是使用空链接,并使用JS控制ID来给按钮添加功能,但是在微信中会导致第一次点击按钮时页面出现重新加载现象……

解决办法如下:

<a href=”javascript:void(0);” class="btn" id="btn"></a>

注:javascript:void(0) 链接无返回值。

当a标签href为空链接,写法为javascript:void(0),也不是说使用href="#none"就是错误的,在pc端上使用也是没有问题的,href="javascript:void(0);是专业化的一种表现,更值得我们去写,毕竟它解决微信中存在的一个bug...